9 Tips for Shorter Laravel Code

preview_player
Показать описание
Some random things that you can write in a shorter way, with various Laravel helpers.

00:00 Intro
00:19 Tip 1. Shorter @if auth()-check()
01:14 Tip 2. Shorter Auth user in Blade
02:37 Tip 3. Shorter @foreach
03:31 Tip 4. Shorter Carbon::now()
04:31 Tip 5. Shorter Log::info() and dd()
06:01 Tip 6. Shorter abort()
07:07 Tip 7. Shorter CSRF and Method
08:05 Tip 8. Shorter Hash::make()
09:12 Tip 9. Shorter redirect()-back()

- - - - -
Support the channel by checking out our products:
Рекомендации по теме
Комментарии
Автор

Day by day this channel becoming gold mine for laravel developer.

pramod
Автор

00:20 - Shorter @if auth()->check()
01:15 - Shorter Auth user in Blade
02:37 - Shorter @foreach
03:31 - Shorter Carbon::now()
04:31 - Shorter Log::info() and dd()
06:01 - Shorter abort()
07:07 - Shorter CSRF and Method
08:05 - Shorter Hash::make()
09:11 - Shorter redirect()->back()

mabdullahsari
Автор

The @if with a @foreach still makes sense for when your results are in a table with headings and you don’t want to show the table unless there are results.

rdvr
Автор

If you're flashing a session whenever user interracts with a model, you can use observer instead of flashing the session manually in every crud methods.

kangzoel
Автор

info() can be seen directly in the debugbar, so no need to look into the Log file :)

KatieGeorgieva
Автор

This videos is really helpful about shorten written functionality of famous laravel development tool thank so much and really appreciated!

protectedfor
Автор

Simple, straight to the point, effective. Amazing video, thanks.

zHqqrdz
Автор

8:55 -- you can set mutator in model to make it more clean.

rahulg
Автор

I cant believe how much knowledge you share. It s inredibcle

x-drake
Автор

best laravel channel ever. thank you man

Fraps
Автор

Thanks for another excellent tutorial. Been a fan of your Laravel contributions for a while. I do want to mention one thing though when you said that sometimes junior developers pass the User from the controller to the view. I actually think it is the opposite. Senior developers understand that you want to remove logic as much as possible from your views and just pass dumb data into views. This makes all your logic testable by checking the data being passed into the view in your tests. In fact I would even go further and say you shouldn't pass the User into the view and instead just pass a user_is_authenticated bit into the view that the view can check. Now in this specific case I don't think doing the auth check using the Laravel helper in the view is bad, because Laravel is a well tested framework. I only want to make sure that the junior developer statement does not make developers think, that pulling logic out of the view and then passing in the resulting data into views, makes them a junior dev.

aregsarkissian
Автор

In order to dump some data in the view, not in the log file while keeping the other code executing, simply use dump() instead of dd()

cardboarddignity
Автор

Thank you, I love this kind of content.

MuhammadArnaldo
Автор

Some of those helpers remove the `use` but they also hide that dependency. When you open the file to read it, you won't know all the dependencies that file has because they are hidden in those helpers.

j.oliveira
Автор

Sir you learned these tips in 5 years of experience. And i uses these tips from first day of laravel😂😂🥰 By the thank you sir for these tips

sportsandstudy
Автор

Great video! I d like more videos like this.

Thanx!!!

raamonmaia
Автор

I like most of these, since they're just a shorter way of doing specific things and a shorter syntax.

The only one I can't recommend is the bcrypt one, since if you DO later decide to change that method of hashing, now you've got more than a config to change and have to find any references to bcrypt in the code.

Everything else is great

JouvaMoufette
Автор

I like making a User::current(); and then depending on the project i'll also have Company::current(); or Team::current(); so i'll have the same syntax for any model that represents the user

itsmillrtime
Автор

I love these series! I feel though that I prefer some amount of verbosity in some of the methods you mentioned. Shorter isn't always better in my opinion.

alzy
Автор

Very useful tips. Kindly make a video on laravel security tips please.

Amit-r