Saturday, March 18, 2017

Laravel return only the first message and only it's content

I am using Laravel 5.4, have ajax that calls a post method which calls the register controller (built in) and returns an error in json format, i want only message to be returned and only it's body: Example:

"first_last_name":["First and last names are required"] => only "First and last names are required" to be returned.

I am fairly new to Laravel and think here its the validation:

$this->validator($request->all())->validate();

I tried using ->messages() and ->first() but i can't seem to make it work.

Thank you



via Pencho Slaveikov

Advertisement