Form validaton Laravel V5.5

open up the CLI or command line, and add this command to it

php artisan make:request StoreBlogPost

Notice: give it a name that is not that same as a model or controller, because you’ll have to add it to the controller.
After then it will create a new file at app/Http/Requests open this file and add this to it

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ];
}

This means that you are validation the title form and the body form of course you can add as many as you want.

at the authorize() method return it as true or add more validation for the authorization there.

public function authorize()
{
return true;
}

at your controller add the file or request name before the $request variable.

Notice: You’ll have to add the request file to this controller so add this: use AppHttpRequestsPostToPage ;

public function store(PostToPage $request)
{ … }

this is all you need to do

CategoriesUncategorized

Leave a Reply

Your email address will not be published.