this is a different approach but a little better in my opinion
Route::bind('project', function($value, $route)
{
return Project::where('slug', '=', $value)->first();
});
Route::get('project/{project}', 'ProjectController@show');
class ProjectController extends Controller {
public function show($project)
{
$project; // Project model
}
}
zenry can you elaborate on your solution? I'm not following it completely :S
I think what zenry is saying, that for exampe if you have
Route::get('project/{project_id}', 'ProjectController@show');
then in you controller you could access project_id by passing variable to the controller like this
class ProjectController extends Controller {
public function show($project)
{
$project; // Project model
}
}
However, if you would add somewhere
Route::bind('project_id', function($value, $route)
{
return Project::where('slug', '=', $value)->first();
});
instean of passing project_id, laravel would pass project object into your controller action.
What if I have a post request, like
Route::post('project', 'ProjectController@show');
and I have project_id in $_POST?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community