9 Tips for Shorter Laravel Code

  Рет қаралды 61,119

Laravel Daily

Laravel Daily

Күн бұрын

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:
- Try our Laravel QuickAdminPanel: bit.ly/quickadminpanel
- Enroll in my Laravel courses: laraveldaily.teachable.com
- Purchase my Livewire Kit: livewirekit.com
- Subscribe to my weekly newsletter: bit.ly/laravel-newsletter

Пікірлер: 117
@pramod9200
@pramod9200 3 жыл бұрын
Day by day this channel becoming gold mine for laravel developer.
@matejcerny4459
@matejcerny4459 3 жыл бұрын
Gold mine? I think diamond mine
@nadeemahmed7947
@nadeemahmed7947 3 жыл бұрын
Offcourse
@smhr145
@smhr145 2 жыл бұрын
True
@alnahian2003
@alnahian2003 Жыл бұрын
It's a pure Kryptonite mine, baby!
@ahmadfaisal6356
@ahmadfaisal6356 Жыл бұрын
Exactly
@rdvr
@rdvr 3 жыл бұрын
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.
@kreaweb-be
@kreaweb-be 2 жыл бұрын
Very nice tips. Thanks.
@MuhammadArnaldo
@MuhammadArnaldo Жыл бұрын
Thank you, I love this kind of content.
@zHqqrdz
@zHqqrdz 3 жыл бұрын
Simple, straight to the point, effective. Amazing video, thanks.
@programming_tips_bd
@programming_tips_bd 2 жыл бұрын
Thank you, it helps lots
@raamonmaia
@raamonmaia 2 жыл бұрын
Great video! I d like more videos like this. Thanx!!!
@salman-804
@salman-804 2 жыл бұрын
Every time i watch your video, i learn something new. Keep up the good work.
@Alejandro5577
@Alejandro5577 2 жыл бұрын
Thanks!! Very useful
@travholt
@travholt 3 жыл бұрын
Love these videos!
@Fraps224
@Fraps224 2 жыл бұрын
best laravel channel ever. thank you man
@TheRetroHome
@TheRetroHome Жыл бұрын
You are the best. Thank you!
@x-drake4153
@x-drake4153 Жыл бұрын
I cant believe how much knowledge you share. It s inredibcle
@mithudas6873
@mithudas6873 3 жыл бұрын
Love this ❤️ Just awesome.
@180695
@180695 2 жыл бұрын
This videos is really helpful about shorten written functionality of famous laravel development tool thank so much and really appreciated!
@muhammadmuneeb4122
@muhammadmuneeb4122 3 жыл бұрын
Quality stuff ❤ thanks man
@marchinton
@marchinton 3 жыл бұрын
I love these videos
@webjaved
@webjaved 3 жыл бұрын
Awesome video!
@khizer3528
@khizer3528 2 жыл бұрын
Excellent stuff ❤️
@ivan.silicin
@ivan.silicin 3 жыл бұрын
Good information, thanks
@chang112x
@chang112x 3 жыл бұрын
This video is gold
@alzy101
@alzy101 3 жыл бұрын
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.
@rubenramirez2710
@rubenramirez2710 3 жыл бұрын
Awesome video
@aomo5293
@aomo5293 3 жыл бұрын
Great tutorial
@llBestBoyll
@llBestBoyll 2 жыл бұрын
cool video 👌🏼
@KatieGeorgieva
@KatieGeorgieva 3 жыл бұрын
info() can be seen directly in the debugbar, so no need to look into the Log file :)
@mabdullahsari
@mabdullahsari 3 жыл бұрын
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()
@LaravelDaily
@LaravelDaily 3 жыл бұрын
I think I've made this list, see the description of this video, or it didn't work for you?
@mabdullahsari
@mabdullahsari 3 жыл бұрын
@@LaravelDaily Mobile :)
@MohAliii
@MohAliii 3 жыл бұрын
Works for me on mobile 👌
@warrenarnold
@warrenarnold 3 жыл бұрын
@@LaravelDaily prolly just he's used to doing that, dont think harm was intended
@JenuelDev
@JenuelDev 2 жыл бұрын
laravel daily is the best!
@rahulg8872
@rahulg8872 3 жыл бұрын
8:55 -- you can set mutator in model to make it more clean.
@eleazarfederio1718
@eleazarfederio1718 3 жыл бұрын
the best laravel channel
@danielcastillo7133
@danielcastillo7133 2 жыл бұрын
Cool, i knew all tips
@raminsadeghnasab9310
@raminsadeghnasab9310 2 жыл бұрын
Good tips,
@user-ku4dv7ri2k
@user-ku4dv7ri2k 3 жыл бұрын
Thanks a lot!
@AkhileshYadav-lv3kh
@AkhileshYadav-lv3kh 2 жыл бұрын
Great sir
@justinphilip4235
@justinphilip4235 3 жыл бұрын
Thank you ♥️
@Rohitkumar-vq1yk
@Rohitkumar-vq1yk 3 жыл бұрын
Thank you sir .. 🙏
@kangzoel8717
@kangzoel8717 3 жыл бұрын
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.
@deastortion
@deastortion 3 жыл бұрын
dude, that's a really good idea
@ekwiz
@ekwiz Жыл бұрын
Great 👌
@aregsarkissian2686
@aregsarkissian2686 3 жыл бұрын
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.
@SergeyNeskhodovskiy
@SergeyNeskhodovskiy 2 жыл бұрын
You make a good point. Overall, I find the entire blade somewhat archaic in front of the JAMStack approach in general.
@cardboarddignity
@cardboarddignity 2 жыл бұрын
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()
@zineddine_haddad
@zineddine_haddad 3 жыл бұрын
Great Content 3>
@Amit-018r
@Amit-018r Жыл бұрын
Very useful tips. Kindly make a video on laravel security tips please.
@LaravelDaily
@LaravelDaily Жыл бұрын
I did already, search on the channel for "security"
@seyidtakele8158
@seyidtakele8158 3 жыл бұрын
I am Happy to be the first viewer of this video .
@qskyisover8153
@qskyisover8153 3 жыл бұрын
Thanks you a lot for your videos, very helpful!
@itsmill3rtime
@itsmill3rtime Жыл бұрын
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
@muhammadfarhanahmed9280
@muhammadfarhanahmed9280 3 жыл бұрын
good content
@j.oliveira
@j.oliveira 3 жыл бұрын
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.
@Jurigag
@Jurigag 3 жыл бұрын
Exactly this, i hate this about laravel community - that they try to use those helpers everywhere. In our projects we use laravel but we try to avoid those helpers as much is possible.
@bubblesort6368
@bubblesort6368 3 жыл бұрын
Yeah) This is rails thinking, write less code at any cost. Laravel inherits that philosophy, but allow write better code with DI)
@GergelyCsermely
@GergelyCsermely 3 жыл бұрын
Thx.
@sportsandstudy6985
@sportsandstudy6985 2 жыл бұрын
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
@alicenNorwood
@alicenNorwood 3 жыл бұрын
yay new tips
@windigo000
@windigo000 3 жыл бұрын
just the tips 😁👍
@JouvaMoufette
@JouvaMoufette 3 жыл бұрын
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
@splasher2119
@splasher2119 3 жыл бұрын
How often do you change encryption methods?
@KokilThapa
@KokilThapa 3 жыл бұрын
Sir please make a video about subdomain in laravel
@GBOfficialVlog
@GBOfficialVlog 3 жыл бұрын
have you use docker for local dev?
@bumblebity2902
@bumblebity2902 3 жыл бұрын
Sir, is auth() helper works with custom coulmns, such as is_admin?
@emailaddress8835
@emailaddress8835 3 жыл бұрын
I love it LARA croft wkwkwkwk👍 thanks sir🙏 GBU
@JonibekJ
@JonibekJ 3 жыл бұрын
awesome tutorial!. Hey Corp how do u scrolling in phpstorm to 4 directions?
@Watchdog8388
@Watchdog8388 3 жыл бұрын
Press Shift key while scrolling
@hemantbhardwaj17
@hemantbhardwaj17 3 жыл бұрын
First time i am feeling good that i already using every helper by my self from this list because of my laziness 🤣 Thanks one question auth()->user() does it hit model Or query every time Or just once? It's better to call it one in the public var?
@nikolaimoiseev8637
@nikolaimoiseev8637 3 жыл бұрын
Hi Author! First of wish to really thank you for what you are doing. In my project every there weren’t any issue, solution to which I couldn’t find on your channel :) Wanted to ask a little bit complex question. I am new to laravel. How do you think, if my goal is to make a simple social network with profiles, news feed and status program , will laravel framework be enough for me, or Laravel is only for more simple CRUD projects?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Laravel can handle any large projects, but it's not the framework that writes the code, so no one can guarantee that your written Laravel code will be optimized
@a-ezzat5677
@a-ezzat5677 3 жыл бұрын
I have a problem with websocket after upgrading to laravel 8, everything is fine except echo which is not listening, in blade, window.Echo.channel("mychannel").listen("eventname",(e)=>{ consile.log(e); #not showing anything although pusher is receiving message and I am seeing event triggered in websocket dashboard page either } would you please help
@minhviet2023
@minhviet2023 3 жыл бұрын
your video is so good, it will be better if you add english subtitle
@AlfredoElizondoLife
@AlfredoElizondoLife 3 жыл бұрын
Just turn on CC on KZbin
@hatsushiroyuki8697
@hatsushiroyuki8697 3 жыл бұрын
Great content as always, didn't knew Hash::make() could be simplified using bcrypt().
@daleryanaldover6545
@daleryanaldover6545 3 жыл бұрын
I was using bcrypt() when laravel was still on version 6 and didn't know there was Hash::make.
@neEs6624
@neEs6624 9 ай бұрын
❤❤
@mallesbixie
@mallesbixie 3 жыл бұрын
Question: Carbon\Carbon or Illimunate\Support\Carbon? Which one and why? Or use the \Date facade?
@JaiShreeRamSitaRamJi
@JaiShreeRamSitaRamJi 6 ай бұрын
@digitzero3613
@digitzero3613 2 жыл бұрын
Maybe its just me but I'd still prefer writing the helper functions with their classes attached because it makes so much more sense while reading through the code.
@Paul-kw4js
@Paul-kw4js 3 жыл бұрын
👏👏
@limhorsimhorn4151
@limhorsimhorn4151 3 жыл бұрын
Can you do laravel lumen microservices
@ruslankandiba
@ruslankandiba Жыл бұрын
💣
@pesovatech6899
@pesovatech6899 3 жыл бұрын
Please which extension do u use that shows the highlight of a function or class when u hover on it..
@LaravelDaily
@LaravelDaily 3 жыл бұрын
I use phpstorm without any extensions.
@dominikjezik303
@dominikjezik303 3 жыл бұрын
There is also an alternative to dd(), which prints a nicer code - ddd() Dump Die Debug
@J-wd2cx
@J-wd2cx 3 жыл бұрын
Or just dump() :)
@michaelkhoussid7673
@michaelkhoussid7673 3 жыл бұрын
@@J-wd2cx That's one extra character, too lazy.
3 жыл бұрын
3:34 Carbon::setTestNow( any carbon date) and now() never work for me when I am phpunit testing. now() always returns the actual system date.
@samuelliam473
@samuelliam473 2 жыл бұрын
im getting some issu can you help me to fix?
@yuliarahma1300
@yuliarahma1300 3 жыл бұрын
how to i redirect to login page after page expired without refreshing the page?
@ilyasayusuf5447
@ilyasayusuf5447 3 жыл бұрын
thx you for the tips, can you do a backend tips for laravel, like creating apis. maybe shorter way to make if($request->has("name");){ array_push($data,$request->name); } .... model::create($data); or maybe the best way to handle the error to the frontend instead of catch then $th->getMessage(); i also notice that in the api routing i can't use resource for all basic controller function or it just me
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Please watch my playlist of Code Reviews on this channel, I touched CRUDs and APIs in a few of them.
@jannusdomingo5681
@jannusdomingo5681 3 жыл бұрын
I wonder where the Auth::user() came from? Is it automatically select the logged in users id and do I need to use the auth command to be able to use it? Thanks and godbless
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Yes it automatically returns the logged in user, full object, not only ID. Another way is auth()->user() returns the same thing If you need only ID, then auth()->id()
@jannusdomingo5681
@jannusdomingo5681 3 жыл бұрын
@@LaravelDaily basically laravel knows the table users column, because of their default User, UserModel etc. when installing a fresh laravel app. I also wonder if I can make a custom Authentication to access other column? Ex: Auth::anothertable()->get_columns
@Fraps224
@Fraps224 2 жыл бұрын
02:37 Sadly this doesn't work with NULL. Or maybe someone can correct me
@TheXambitoGames
@TheXambitoGames 3 жыл бұрын
Auth::id() 😎
@bmtamim7818
@bmtamim7818 3 жыл бұрын
Hello sir, We want a video about" how to cofigure a laravel project on shared hosting " I have research and saw some video, They told that move index file from public to root. But l think its not a good idea. And I believe yoi will tell us a best way to configure/upload laravel project on shared hosting. Please give this video as a next daily video.😍.. Please sir.
@LaravelDaily
@LaravelDaily 3 жыл бұрын
I strongly advice AGAINST shared hosting for any Laravel project, if possible.
@bmtamim7818
@bmtamim7818 3 жыл бұрын
@@LaravelDaily Yeah, its not good sir, But I have nothing to do, I am not eligible (financial problem) to purchase a VPS. 😓 IF you can make a video then it will be really appreciate. If you haven’t shared hosting, you can use my hosting. For Videos.. Thanks for the reply sir.😍
@shocchosolutions6275
@shocchosolutions6275 3 жыл бұрын
sir eloquent relationship shortcode video, please please
@LaravelDaily
@LaravelDaily 3 жыл бұрын
What do you mean by "relationship shortcode"?
@shocchosolutions6275
@shocchosolutions6275 3 жыл бұрын
@@LaravelDaily like sir easy and short ways to do any relationship with 2 or multiple models
@LaravelDaily
@LaravelDaily 3 жыл бұрын
@@shocchosolutions6275 I guess it's all in Laravel documentation, I can't make it easier or shorter than this :)
@rahulji6565
@rahulji6565 3 жыл бұрын
Local Taylor Otwell
@thatsenam9183
@thatsenam9183 3 жыл бұрын
TailwindCSS, Thousan of line repeated messed up - No Problem Php (inside blade) 2 line of if else - Its time to Fixed up things. 😁
@j.oliveira
@j.oliveira 3 жыл бұрын
You only repeat the css if you want. Use components. It's easier to use and manage. ;)
@Jurigag
@Jurigag 3 жыл бұрын
I will be honest - most of the time shorter doesn't mean better. Especially using helpers is kind of bad for better quality of code.
@tim.bogdanov
@tim.bogdanov 2 жыл бұрын
shorter does not always mean better.
@object_name
@object_name 3 жыл бұрын
Am i the only one that thinks, some of these helpers should not be used. For me they sometimes make it harder to work on the code, because you can just access them anywhere. For example the "auth()" - helper. It could be used in some blade component deep inside the navigation for example to link to the user profile without you knowing that the component requires the user to be authenticated. Breaking the code in a not authenticated environment. Also : abort_if, throw_if and alikes never felt natural to me especially since the IDE does not seem to support the control flow form for syntax highlighting and deduction of variable types. I in general prefer a few characters more to achieve some expressiveness where necessary.
@kirayamato6128
@kirayamato6128 2 жыл бұрын
Php are so bad at logging at command line. At my point i use laravel and logging some variables are stored in storage folder which in my case i don't want to. That's why i use symfony package "console output" so that it will output the variables in command line/cmd. But in most cases i doesn't accept arrays which is bullshit for me. In other programming languages like java, you can just use *println* in any variables you want to output in command line and it accepts string, obejcts or arrays. Simple as that. I don't know why PHP is like that lol
Laravel Junior Code Review: 12 Tips on Everything
15:30
Laravel Daily
Рет қаралды 74 М.
PHP in 60 Seconds: The Basics #php #project #technology
1:00
Dave Hollingworth
Рет қаралды 377 М.
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 30 МЛН
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 126 МЛН
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 52 МЛН
1❤️
00:17
Nonomen ノノメン
Рет қаралды 13 МЛН
Junior Code Review: Better Routes, CRUDs and Validation
17:58
Laravel Daily
Рет қаралды 58 М.
Exceptions in Laravel: Why/How to Use and Create Your Own
12:18
Laravel Daily
Рет қаралды 86 М.
Learn TypeScript Generics In 13 Minutes
12:52
Web Dev Simplified
Рет қаралды 235 М.
Laravel First Impressions From A JavaScript Dev
21:08
adamdotdev
Рет қаралды 122 М.
Laravel: Repository Pattern in practice
27:13
Przemysław Przyłucki
Рет қаралды 10 М.
Refactor "Senior" PHP Code with Early Returns
12:09
Laravel Daily
Рет қаралды 26 М.
Junior Code Review: Cleaning Up Laravel CRUD
14:54
Laravel Daily
Рет қаралды 68 М.
Laravel + Livewire todo app (and so much more)
16:41
Aaron Francis
Рет қаралды 35 М.
Порезал бассейн, краш тест
0:32
ЗВЕРЬЕ
Рет қаралды 3,8 МЛН
Tiny motor, big power
0:25
Rob Rides EMTB
Рет қаралды 34 МЛН
Speed punched Messi 🫢🥊
0:50
GoalAntics
Рет қаралды 13 МЛН
Черешня из Китая размером с КУЛАК: На стероидах?
0:12
Собиратель новостей
Рет қаралды 6 МЛН
Дарю Самокат Скейтеру !
0:42
Vlad Samokatchik
Рет қаралды 2,3 МЛН