Support the ongoing development of Laravel.io →
Requests Session
Last updated 3 months ago.
0

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}', '[email protected]');


class ProjectController extends Controller {

    public function show($project)
    {
          $project; // Project model
    }

}
Last updated 3 months ago.
0

zenry can you elaborate on your solution? I'm not following it completely :S

Last updated 3 months ago.
0

I think what zenry is saying, that for exampe if you have

Route::get('project/{project_id}', '[email protected]');

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.

Last updated 3 months ago.
0

What if I have a post request, like

Route::post('project', '[email protected]');

and I have project_id in $_POST?

Last updated 3 months ago.
0

Sign in to participate in this thread!

LaraJobs

Your banner here too?

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.