I want to make an AngularJS webapp that uses Laravel as the back-end. Angular will do most of the work regarding controllers and views. And Laravel will primarily be used as a REST API that does user authentication and authorization, model data validation and persistence and finally returning json (most of the time anyway).
So I've been reading the docs of both libraries and I'm getting some ideas on how I can maybe make the back-end very streamlined for my purpose. But I've never made anything like this before, so I'm aware that my ideas might actually be a bit stupid. That's why I want to ask what you guys think.
I'm coming from CakePHP and there I was used to routes being automatically connected if they followed their conventions. So any URL that conformed to a pattern like /controller/action/arg1/arg2/etc was automatically connected and you didn't need to define that route for every single controller@action. I want to do the same for my project in Laravel, but even a bit more extensive.
Basically I want to tell Laravel to handle every route as a resource request via the conventions that Laravel already uses when you define a specific resource. So that GET /posts/3 will automatically connect to PostsController@show(3) without me needing to define that. And I want to go even a bit further. Since most resource controllers do exactly the same thing in their actions, I would like to create a fallback controller that does the same thing whenever a certain controller@action doesn't exist. That way I only have to create a controller-action when it has to do something special.
That's it for now. What do you guys think about this so far?
Sounds like a good use of inheritance. When you say "fallback" controller, I think you really just mean making each controller extend some base controller that has a bunch of default logic in it, then override where necessary, sounds fairly straightforward.
Well, that's not exactly what I meant. I actually meant that if I don't want to override any of the functions of the fall-back controller then I see no point in making a controller at all. Not even an empty one.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community