"Cruddy by Design" - Adam Wathan - Laracon US 2017

Adam Wathan · 88K views · 2017 · 40:30

Open on YouTube

Web developmentSoftware architecture & designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when someone's Laravel controllers have grown custom methods or messy routes and need a way to restructure them into RESTful resources.

Recommended by 10 people across 10 different months, 2017 to 2024.

What it is

Adam Wathan's Laracon US 2017 talk argues for keeping Laravel controllers to the standard CRUD actions (index, create, store, show, edit, update, destroy). Extra behaviour such as publishing a podcast moves into its own resource controller instead of adding custom methods. It is a 40-minute conference talk with source code on GitHub.

What people said

Recommends user3451822 · 2017-01 · Stack Overflow · on “Route and view naming conventions”

For the get routes, I would normally put the views in a directory structure matching the route name. E.g. resources/views/teams/team/manage/index.blade.php . However, I feel that this is way too verbose. I agree. From the Laravel docs [LINK] : Laravel uses the typical RESTful "CRUD" approach when assigning resource routes to a controller. Each verb (i.e. GET, POST, PUT, DELETE) gets a designated URI , an action (technically, a controller method) and a route-name (sometimes, /path/to/blade/view ). So, from your snippet: // return view(teams.index) Route::get('/teams', 'TeamController@index'); // return view(teams.create) Route::get('/teams/create', 'TeamsController@create'); // redirect('/hom

Recommends Jerico Pulvera · 2017-09 · Stack Overflow · on “Laravel using separate controller for separate logic”

[this video] This talk is a bit advance about controllers but it is surely a good practice regarding controllers.

Recommends patricus · 2018-01 · Stack Overflow · on “Laravel 5.4 Getting MethodNotAllowedHttpException when doing POST request”

@wendecat Well, the best option would be to restructure everything so that you conform to normal resource routing. This talk [this video] by Adam Wathan gives you the idea. But, that can take a bit of time and effort. If you just want a quick workaround to get around this, just allow your route to handle GET requests, too.

Recommends Junaid Qadir Shekhanzai · 2018-06 · Stack Overflow · on “MethodNotAllowedHttpException in laravel-5.6 with Ajax”

use crud actions like `create` instead of `save` then `Route::post('/subscription/, `Scubscription@create`)` even better use resource: `Route::resource('/subscriptions', 'SubscriptionsController')`; If you have time watch these two videos to better design your API [this video] [LINK]

Recommends Jon Blow · 2018-11 · Stack Overflow · on “Should I Nest Routes to Resources in Laravel?”

This might be a bit of a deviation from the original question, but I feel that Adam Wathan's Laracon US 2017 talk might be a useful resource for this discussion. ( [this video] ) I am relatively new to development and therefore explore a lot of code bases on github. I always struggle to understand nested routes. So as a best practice I would prefer no-nesting to nesting. Keeping stuff "CRUDY by design" as Adam calls it, one thing you achieve, imo, is simplification of route names. If I were to work in a group, that is a pattern I would prefer. However, referring to the penultimate paragraph on your question, I struggle to understand why an integrity check is not needed.

Recommends Rwd · 2019-01 · Stack Overflow · on “Relationship not returning any data”

@n1njac0de No, you don't need to but some people like this approach as it means (amongst other things) you can have more semantically correct controllers: [this video]

Recommends Clément Baconnier · 2019-03 · Stack Overflow · on “Which HTTP request should I use while using updateOrCreate() method in Laravel?”

In supplement of my answer: I can recommend you Adam Wathan conference talk about organizing the controllers [this video] It's not a direct answer to your post but it help

Recommends mdexp · 2019-06 · Stack Overflow · on “REST - Nested resources and controllers & Laravel”

Quick suggestion: I suggest you to take a look at this talk [this video] by Adam Wathan at Laracon 2017. It should give you an example on how to refactor your controllers/routes to adhere more to the REST standard and maybe clarify your doubts

Recommends tamrat · 2020-02 · Stack Overflow · on “Laravel: Can I add custom method to API Controller that routed by api.php?”

You can. You just need to define those routes in your routes/api.php file. routes/api.php Route::group(['middleware' => ['api']], function(){ Route::resource('myTable', 'Api\MyApiController'); // Define new routes like this Route::get('myTable/MyMethod/{id}', 'Api\MyApiController@myMethod'); }); Update Even though its perfectly fine to define routes with custom method names (other than the basic CRUD ones) in such a way, it can often lead to overpopulated controllers. Check out this [this video] interesting talk by Adam Wathan about this issue.

Recommends francisco · 2024-05 · Stack Overflow · on “Dynamic url calling using slug failed in Laravel”

I recommend that you watch this [this video] old but good video. those routes are only possible with more on URI, check docs [LINK] how the do it.