The missing route in Laravel Route::resource…

The Route::resource method in routes.php Laravel 5 is brilliant. It saves time setting up simple CRUD routes and consolidates lots of routes into one method.

However, I’m not sure the Create and Update route both have a pre-route for the form however Destroy doesn’t?

I know the Store and Update commands both need to have a form of data fed to them, however… all my Destroy commands need a page to check the user is sure they want to delete the resource. So all my routes resource calls have this “delete” GET with them,

Route::resource('taxonomy', 'TaxonomyController');
Route::get('taxonomy/{id}/delete', [
'as' => 'taxonomy.delete', 'uses' => 'TaxonomyController@delete'
]);

Otherwise, people are tempted to use a Javascript confirm box as the only way to check people want to delete something first. However, that’s a bit dumb 🙂 JS alert boxes are fiddly, also don’t fit with most site’s design styles and if your browser has JS off, your user is screwed.

Author: Dan Course

Dan Course, E-Learning Development at Warwick University (WMG). Agile Scrum trained and full-stack development. Interested in E-learning, Democracy, Politics and Tech. All thoughts are mine and not of my employer.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s