mercredi 23 septembre 2015

Laravel 5 Loading Project based on ID

I have used resourceful routing for my Project model

Route::model('projects', 'Project');
Route::bind('projects', function($value, $route) {
    return App\Project::whereId($value)->first();
});
Route::resource('projects', 'ProjectsController');

This all works fine, and I have access to all the functions. So if I go to

http://localhost:8000/projects

I can see all the projects. If I do something like

http://localhost:8000/projects/24

I can see project with the id 24.

Now on my projects page, I have a load project button. The idea is that the user enters the id of the project they want to see, and it will take them to the show page of this project. So I added an additional route

Route::get('projects/{projects}', array('as' => 'projects.loadProject', 'uses' => 'ProjectsController@loadProject'));

The problem is that this route gets the same url as a show page. Therefore, if I now go to the show page for project with the id 24, I now get an empty page. So it looks like this route is now overriding the show route.

How can I set it up to load a project based on an id?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire