Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kris01's avatar

Validator Laravel

Where can I put my validator to avoid typing it twice for storing and updating a table? Where is the right place to put it? and make it reusable

0 likes
7 replies
Kris01's avatar

@Sinnbeck how should I name a form request for example if I want to validate an 'Employee'?

Kris01's avatar

@Sinnbeck why is this happening ? error

Target class [App\Http\Controllers\StoreEmployeeRequest] does not exist.

code

/**
        * @param  App\Http\Requests\StoreEmployeeRequest  $request
        * @return Illuminate\Http\Response
    */
    public function store(StoreEmployeeRequest $request){
        
        $employee = new Employee();
        $statuses = $employee->getStatuses();
        $shiftTypes = $employee->getShiftTypes();

        $validated = $request->validated();
        ......
		}

It's giving a wrong path

Sinnbeck's avatar

@Kris01 it works exactly the same as if I were to add validation in the controller method directly

Please or to participate in this conversation.