[Vuejs]-Laravel: FormRequest validation failing when I add required rule

0👍

Try something like this and see if you get same error:

   <?php

      namespace App\Http\Requests\bulletins;

      use App\Http\Requests\Request;

      class CreateBulletin extends Request
      {
        /**
        * Determine if the user is authorized to make this request.
        *
        * @return bool
        */
        public function authorize()
        {
               return true;
        }

        /**
        * Get the validation rules that apply to the request.
        *
        * @return array
        */
        public function rules()
        {
           return [
             'image' => 'nullable|sometimes|image|mimes:jpeg,bmp,png,jpg,svg|max:2000',
             'title' => 'string|min:5|max:250',
             'body' => 'string|min:5|max:250',
           ];
        }
   }

Need to remove FormRequest from class to remove that error you got after replacing Request.
Hope this helps.

0👍

Before set the values you have to test the request using:

$validated = $request->validated();

then(for example the title field which has a rule in the form request):

$bulletin->title = $validated->input('title');

Make sure of the imports in the controller also:

use Illuminate\Http\Request; for the request; 

and

use App\Http\Requests\CreateBulletin;

Leave a comment