I recently came across this video from the US Laracon 2017 with Adam Wathan on "Making your applications cruddy by design". His talk is about cleaning up your controllers with the guideline: "if it isn't part of the basic Restful methods of that controller, create a new controller." In the third sec...
I am in the process of simplifying a website, and one of the redesign concepts has been: "only ask one thing of the user per page". Users on our website create a Scan (but it could just as well be an Article, Item etc.) Instead of asking the user for all of the information on one page, we're now ask...
My nested Vue components - which emulate my related Laravel models - are sending out a ton of requests. Each component is currently responsible for retrieving it's own data. With 15 items in 3 categories and 1 main component that's already 19 requests. And for those 15 items each need to pull in an...
I am trying to allow users to edit their playlist. However, whenever I try to execute the PATCH request, I get the MethodNotAllowedHttpException error. (it is expecting a POST). If I remove 'method' => 'PATCH' from Form::open, but leave the route pointing to update, it still executes the store actio...
Nice, there are a few thing in here I didn't know and that will come in handy. I just don't know if I'll ever feel comfortable touching my parent child relationship...
I'm not going to read 100+ books in 2016. Even the author is only reading a maximum of 12 books this year, and has only "at least started a couple of chapters" in the "majority of the books".
I know it's fun to have a decked out design library. But I'd rather have a few really solid and personal recommendations than this random list of "classics".
I don't think your problem is that web.php is too big at all. I think the issue is that your controller methods are overly complicated. If you create semantically better (and simpler!) controllers, your web.php will become semantically clearer and easier to manage.
Currently you have only 2 controllers: BlogController and CmsController. I understand the instinct to do this, but common practice (and the way Laravel is set up) is to have your Controllers control a Model. And since indexing/storing/creating Blog and Cms Model's don't make much sense (and you probably don't have those models in your project), I'd much rather see UsersController, PostsController, Pagesontroller, CommentsController, UserPostsController, etc. Here, indexing/storing/creating/etc Users, or Posts makes a lot of sense. Also, having the controllers freed up from the context of being either part of the CMS or part of the Blog will allow your controllers to be much more versatile (especially once you're working with API calls).
Try doing this: whenever you create a Controller, for example PostsController, create it with php artisan make:controller PostsController --resource, and try to stick to the provided methods only. Now, for your routes in web.php you can be explicit:
Route::get('/post', 'PostsController@index')->name('post.index');
Route::get('/post/{post}', 'PostsController@show')->name('post.show');
etc.
Or you could you could use
Route::resource('post', 'PostsController');
Which will automatically create all 7 routes corresponding with your 7 controller methods. This will greatly increase the readability and manageability of your web.php.
-- next steps --
Now, if you want to list all posts by a certain user, that won't fit in either PostsController or UsersController, but you can create a new controller: UserPostsController(as a resource), and now you have acces to:
Route::get('/user/{user}/post', 'UserPostsController@index')->name('user.post.index');
or
Route::resource('user.post', 'UserPostsController');
And Route::resource here will automatically generate nested routes to your controller methods.
Nice, there are a few thing in here I didn't know and that will come in handy. I just don't know if I'll ever feel comfortable touching my parent child relationship...
I'm not going to read 100+ books in 2016. Even the author is only reading a maximum of 12 books this year, and has only "at least started a couple of chapters" in the "majority of the books".
I know it's fun to have a decked out design library. But I'd rather have a few really solid and personal recommendations than this random list of "classics".
...and three books by Stephen Hawking?
It reminds me of Simurai's business cards from about 3 years ago. His slices also fall upwards. Here's the 'cutting of' video ;)
This is really awesome, I love it! Whoever made this has a great sensitivity for modern design, and managed to merge it beautifully with the music.
Mesmerizing!
I don't think your problem is that web.php is too big at all. I think the issue is that your controller methods are overly complicated. If you create semantically better (and simpler!) controllers, your web.php will become semantically clearer and easier to manage.
Currently you have only 2 controllers:
BlogControllerandCmsController. I understand the instinct to do this, but common practice (and the way Laravel is set up) is to have your Controllers control a Model. And since indexing/storing/creatingBlogandCmsModel's don't make much sense (and you probably don't have those models in your project), I'd much rather seeUsersController,PostsController,Pagesontroller,CommentsController,UserPostsController, etc. Here, indexing/storing/creating/etcUsers, orPostsmakes a lot of sense. Also, having the controllers freed up from the context of being either part of the CMS or part of the Blog will allow your controllers to be much more versatile (especially once you're working with API calls).Try doing this: whenever you create a Controller, for example
PostsController, create it withphp artisan make:controller PostsController --resource, and try to stick to the provided methods only. Now, for your routes in web.php you can be explicit:Or you could you could use
Which will automatically create all 7 routes corresponding with your 7 controller methods. This will greatly increase the readability and manageability of your web.php.
-- next steps --
Now, if you want to list all posts by a certain user, that won't fit in either
PostsControllerorUsersController, but you can create a new controller:UserPostsController(as a resource), and now you have acces to:And
Route::resourcehere will automatically generate nested routes to your controller methods.