jeudi 2 mai 2019

Validation error in api response in laravel 5.6

I want to store data through api. It's working but problem is when I add validation it does not give me corresponding message . How can I fix it? Thanks in advance

Here is my route

Route::post('api/add_user', 'TestApiController@store'); 

Here is my controller

public function store(Request $request)
{

    $validation = Validator::make(Request::all(), [
        'name' => 'required',
        'phone' => 'required',
        'email' => 'required'
    ]);


    if ($validation->errors()) {
        return $errors->toJson();
    } else {
        $testApi = new testApi();


        $testApi->name = $request->name;
        $testApi->phone = $request->phone;
        $testApi->email = $request->email;

        $testApi->save();


        return "ok";
    }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire