Laravel Controller Structure: Invokable Class with Protected Methods

preview_player
Показать описание
Let's learn from one example by Spatie, I liked how they structured a Controller in one of their packages.

Related links:

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

getAuthenticatable() is actually a good name as it returns an instance of a class that implements the Authenticatable interface, defined by Laravel. So the name precisely says what the method does. Now of course, it's up to the person reading the code to understand how Laravel authentication works, using this Authenticatable interface. But that's not the job of the person writing the code of this package controller. It has to be assumed that the reader of the code understands the core classes and interfaces of the framework.

The Laravel User class implements Authenticatable but it's perfectly possible to specify a different class that implements Authenticatable. This can easily be done by setting the class to be used in the login-link.php config file.

theceilidhboy
Автор

For all the junior devs out there: look how the code is containing any comment, but it's still super readable. You don't hav to put comments, instead write readable code.

giacomogaravaglia
Автор

mostly good tips, one of your most useful videos for now

in most popular programming languages this case is important; dont write all the logic in one function with tons of variables, cause your code then will be an absurdly hard to read

use functions for each the logic operation with data, give them correct semantic names and all the programming for you will be easy thing for you

have a nice day

sashko_guz
Автор

Wow... I appreciate this video. Thanks for another great one Povilas.

bernardonigbinde
Автор

in large projects it is much more convenient to use the policy

artyomman
Автор

I think, all that protected method can have their own class. Maybe LoginLinkService. More cleaning controller and the service class can be tested.

ericknyoto
Автор

If I see other packages (well I don't see much) but I never find they use Service, Action, or Repository pattern.
But in project we always use it, especially for resuable code.
I have never create packages yet, but this is looks a little different. Not sure why?

bboydarknesz
Автор

good morning... i bought the couse laravel 9 vue 3 crud.. very good and helpfull. how to use compaseble if you have data to insert in several tables with relationships beetwen then

pauloclara
Автор

Hi, Povilas,
I have a situation were there are two types of user: 1. Customer, 2:Admin - Customer can create orders from customer panel and admin can also create orders from admin panel. A user can be both customer and admin (same email). It should have impersonate customer feature in Admin panel. What is the best way to handle authentication?

alpeshrathodcreatives
Автор

Can you explain when to use private methods and when to use protected methods?

SKS