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.
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.
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.
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.
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.
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
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 not often, but it can happen. why having to change if you can write future-proof code with 10 additional characters? you will certainly spend most time doing the change when the time comes than you need to write those 10 extra characters.
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.
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.
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?
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?
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
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
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 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.😍
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
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
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()
@@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
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.
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
Day by day this channel becoming gold mine for laravel developer.
Gold mine? I think diamond mine
Offcourse
True
It's a pure Kryptonite mine, baby!
Exactly
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()
I think I've made this list, see the description of this video, or it didn't work for you?
@@LaravelDaily Mobile :)
Works for me on mobile 👌
@@LaravelDaily prolly just he's used to doing that, dont think harm was intended
info() can be seen directly in the debugbar, so no need to look into the Log file :)
8:55 -- you can set mutator in model to make it more clean.
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.
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.
dude, that's a really good idea
This videos is really helpful about shorten written functionality of famous laravel development tool thank so much and really appreciated!
Simple, straight to the point, effective. Amazing video, thanks.
I cant believe how much knowledge you share. It s inredibcle
best laravel channel ever. thank you man
the best laravel channel
laravel daily is the best!
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()
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.
You make a good point. Overall, I find the entire blade somewhat archaic in front of the JAMStack approach in general.
Thank you, I love this kind of content.
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.
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.
Yeah) This is rails thinking, write less code at any cost. Laravel inherits that philosophy, but allow write better code with DI)
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
Great video! I d like more videos like this.
Thanx!!!
This video is gold
You are the best. Thank you!
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
How often do you change encryption methods?
@@splasher2119 not often, but it can happen. why having to change if you can write future-proof code with 10 additional characters? you will certainly spend most time doing the change when the time comes than you need to write those 10 extra characters.
Very nice tips. Thanks.
Thank you, it helps lots
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
Very useful tips. Kindly make a video on laravel security tips please.
I did already, search on the channel for "security"
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.
Thanks!! Very useful
I love these videos
Awesome video!
Great tutorial
Excellent stuff ❤️
I am Happy to be the first viewer of this video .
Cool, i knew all tips
Good information, thanks
Thank you sir .. 🙏
Love these videos!
Awesome video
Love this ❤️
Just awesome.
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.
Quality stuff ❤ thanks man
thank you sir
Great sir
Thank you ♥️
Great content as always, didn't knew Hash::make() could be simplified using bcrypt().
I was using bcrypt() when laravel was still on version 6 and didn't know there was Hash::make.
Thanks a lot!
Good tips,
cool video 👌🏼
There is also an alternative to dd(), which prints a nicer code - ddd() Dump Die Debug
Or just dump() :)
@@J-wd2cx That's one extra character, too lazy.
Thanks you a lot for your videos, very helpful!
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?
Sir please make a video about subdomain in laravel
your video is so good, it will be better if you add english subtitle
Just turn on CC on RUclips
Great 👌
Great Content 3>
yay new tips
have you use docker for local dev?
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?
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
just the tips 😁👍
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.
Thx.
Question: Carbon\Carbon or Illimunate\Support\Carbon? Which one and why? Or use the \Date facade?
good content
Can you do laravel lumen microservices
What could be more readable than a plain conditional expression?
awesome tutorial!. Hey Corp how do u scrolling in phpstorm to 4 directions?
Press Shift key while scrolling
02:37 Sadly this doesn't work with NULL. Or maybe someone can correct me
Sir, is auth() helper works with custom coulmns, such as is_admin?
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
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.
I strongly advice AGAINST shared hosting for any Laravel project, if possible.
@@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.😍
how to i redirect to login page after page expired without refreshing the page?
Please which extension do u use that shows the highlight of a function or class when u hover on it..
I use phpstorm without any extensions.
❤❤
im getting some issu can you help me to fix?
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
Please watch my playlist of Code Reviews on this channel, I touched CRUDs and APIs in a few of them.
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
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()
@@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
❤
👏👏
sir eloquent relationship shortcode video, please please
What do you mean by "relationship shortcode"?
@@LaravelDaily like sir easy and short ways to do any relationship with 2 or multiple models
@@shocchosolutions6275 I guess it's all in Laravel documentation, I can't make it easier or shorter than this :)
💣
Auth::id() 😎
TailwindCSS, Thousan of line repeated messed up - No Problem
Php (inside blade) 2 line of if else - Its time to Fixed up things. 😁
You only repeat the css if you want. Use components. It's easier to use and manage. ;)
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.
shorter does not always mean better.
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.
Local Taylor Otwell
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