Support the ongoing development of Laravel.io →
IOC Validation Architecture

I've bound a model to a route parameter:

$this->model('employee', 'App\Employee');

This is working fine. The model is injected in my controller method. But now i want to access that model in the authorize method of my FormRequest object:

/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    // TODO: How to get employee model here?
    return true;
}

I've checked the request object, but there's no option. Any suggestions?

Greetings.

Schnoop

Last updated 2 years ago.
0
Solution

Hi, have you tried this inside your authorize method:

$employee = $this->route->parameter('employee');
var_dump($employee);

Cheers!

Last updated 2 years ago.
0

Thanks a lot. It was a bit tricky due to usage of controller routes.

get('employee/hire/{employee}', 'App\EmployeeController@getHire');
post('employee/hire/{employee}', 'App\EmployeeController@postHire');
Route::controller('employee', 'App\EmployeeController');
Last updated 2 years ago.
0

A little advice: avoid implicit routing as much as possible.

Regards,

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Schnoop schnoop Joined 27 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.