In Laravel 7 fetching a model was pretty straightforward, i just needed to setup mi resource route and make a get to the address:
http://localhost/test/public/employee/1
But i cant make it work on Laravel 8, according to my understanding i just need to do this:
public function show(Employee $employee) { dd($employee); }
But dd only returns an empty class:
If i do this:
public function show(Employee $employee) { dd(Employee::find(1)); }
dd returns the correct data:
Route::resources([ 'employee' => EmployeeController::class, ]);
Can somebody help me find what am i missing?
Regards…
Advertisement
Answer
The problem was that i was naming the routes in spanish:
Route::apiResource('empleados', EmployeeController::class);
And because of this Laravel is expecting to receive the model encapsulated in a spanish verb class (empleados instead of employee), So i needed to rename the parameter inside the method controllers to receive the correct model:
public function show(Employee $empleado) { return $empleado; }