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
Hi, have you tried this inside your authorize method:
$employee = $this->route->parameter('employee');
var_dump($employee);
Cheers!
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');
A little advice: avoid implicit routing as much as possible.
Regards,
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community