mardi 27 août 2019

Controller Method not called with custom Form Request Method

For form validation I made a Request class via php artisan make:request UpdatePlanRequest.

However after using the UpdatePlanRequest class in store the method isn't called anymore.

The UpdatePlanRequest:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

abstract class UpdatePlanRequest extends FormRequest
{
    /**
     * 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()
    {   //TODO: CHECK IF THE PROTOTYPE IDS ARE OWNED BY THE USER (https://stackoverflow.com/questions/42662579/validate-an-array-of-integers/42693970)
        return [
            'start_date' => 'required|date',
            'end_date' => 'required|date|after:start_date',
            'name' => 'required|string'
        ];
    }
}

The controller method:

use App\Http\Requests\UpdatePlanRequest;

public function store(UpdatePlanRequest $request)
    {
        //
        dd('hello');
    }

If the function header is store(Request $request) hello is shown, in that example it isn't.

The custom Request class is necessary to call $request->validated(); later for validation purposes according to the docs.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire