phplaravelformsbackendlaravel-artisan

post method dont send data with FormRequest laravel9


profile controller :

 public function store(ProfileRequest $request)
   
    {     dd($ProfileRequest);
        $formFields= $request->validated() ;
       
        $formFields['option'] = $request->input('option');
        $formFields['password'] = Hash::make($request->password);
        
        $profile=Profile::create($formFields);
        return  redirect()->route('login')->with('success','profil ajouté avec succes !');
    
    }

FormRequest :

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

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => 'required|between:5,10',   //|max:10    
            'email' => 'required | email | unique:profiles',
            'password' =>'required |min:8|confirmed', 
            'bio' =>'required',
            'image' => 'image|mimes:png,jpg,svg,jpeg|max:10500',
        ];
    }
}

i use resource method for routes when i try to submit the Form noting returned :

 <form method="POST" action="{{route('Profiles.store')}}">
        @csrf
      /.. inputs here../
    </form>

when i trye to change

public function store(ProfileRequest $request)
to 
function store(Request $request)

i reserve data but when i still using the first noting return


Solution

  • Use dd($request->all()); insted of dd($ProfileRequest); for debugging.

    I see you are upload image so add enctype="multipart/form-data" in form tag Like this <form method="POST" action="{{route('Profiles.store')}}" enctype="multipart/form-data">