Do you think I should create more code review tutorials? Let me know! Follow me or subscribe to my newsletter to get notified when my course is released: - Twitter: twitter.com/codewithdary - Instagram: instagram.com/codewithdary/ - Blog: blog.codewithdary.com/
Both options work fine, there isn't a right or wrong right here, I'm just not really a fan of it. I prefer to explicitly define and insert data into the database. Completely fine using the other method.
Hello dary, thanks for the review and for the corrections, i'll make sure to apply them in my next versions. Again thanks a lot, it means a lot. Keep it up!
That is correct. The source code will not get into the method if the validation passes, so it does not really matter whether you use the $request validated or the values directly.
That's a good video! But I have a few points that concerns me. If you injected FormRequest class instead of general Request, then you don't need to call "$request->validated()" to trigger validation. It would be taken care of by Laravel itself. I think it's not a good point to use "auth()" helper inside any models function - it seem not obvious and has it's own issues. I would use "$this" instead. For me it seem more convenient.
Yes, that is true in Laravel. If you inject a FormRequest class instead of the general Request class, you don't need to call "$request->validated()" to trigger validation. Laravel automatically handles the validation process when using FormRequest classes.
@avfr Observers are simply listeners for model events. You can't choose to use one or the other. You also cannot manually fire model events from a controller, since they're internally fired by eloquent.
putting $guarded=[] (empty array) in the model is same as $fillable=[..all request keys here..] and i think you cant put both of these two variables in the same model
I'm pretty sure you can't because these two properties are used to specify which attributes are mass assignable and which are not, respectively. Well, you technically can, but Laravel will prioritize $guarded and ignore $fillable, which could lead to unexpected behavior in your application.
The ->value method is used to retrieve the underlying value of an enum instance. Enums in Laravel are implemented as objects, and ->value allows you to access the actual value stored within the enum rather than the enum object itself!
The main difference between the two methods is that foreignId() is a shorthand method that automatically creates a column with an unsigned big integer data type and adds the foreign key constraint to that column. This can simplify the syntax of creating a foreign key constraint.
Just was wondering if didn't make a typo, because as i knew $request->validated() returns only validated data from a request and not do validation it self. For validation, i was using $request->validate().
@@codewithdary If I understand correctly validation as a formrequest then the data is always validated behind the scenes. When you use request->validated() then you only return validated data but you don't assign it anywhere. It makes no sense to me to use this method in your example.
Do you think I should create more code review tutorials? Let me know!
Follow me or subscribe to my newsletter to get notified when my course is released:
- Twitter: twitter.com/codewithdary
- Instagram: instagram.com/codewithdary/
- Blog: blog.codewithdary.com/
Hi Dary, I hope you continue with this series as someone who is still learning Laravel you gave alotof great tips.
Thank you Jack! If the video performs well (and it's doing right now) I will definitely continue on making more of these!
This channel is a goldmine, you dont get to see these type of reviews and content unless its premium content, glad that i found it
Thank you so much for the compliments, means the world to me
Great, please continue with this kinda series. Thanks so much, Dary.
Will do, thank you so much!
Much informative Dary. Definitely looking to more of your code review tutorials.
Thanks, will do Peter!
promise fulfilled! Thank you mr Dary and looking forward to having more tutorials like this.
Appreciate the kind words Bashar. If it performs well, I will definitely continue on making content like this!
Hey Dary, At 22:33, the "validated" method is more convenient than the "only" method.
Both options work fine, there isn't a right or wrong right here, I'm just not really a fan of it. I prefer to explicitly define and insert data into the database. Completely fine using the other method.
Dude your videos are great, you'll be at 100k subscribers in no time!
Thank you so much Gavin, I hope so!!
Hello dary, thanks for the review and for the corrections, i'll make sure to apply them in my next versions. Again thanks a lot, it means a lot. Keep it up!
Appreciate it, keep on going with the good work!!
$request->validated() returns only validated fields. You can safly use $model->update( $request->validated() ) i think...
That is correct. The source code will not get into the method if the validation passes, so it does not really matter whether you use the $request validated or the values directly.
That's a good video!
But I have a few points that concerns me.
If you injected FormRequest class instead of general Request, then you don't need to call "$request->validated()" to trigger validation. It would be taken care of by Laravel itself.
I think it's not a good point to use "auth()" helper inside any models function - it seem not obvious and has it's own issues. I would use "$this" instead. For me it seem more convenient.
Yes, that is true in Laravel. If you inject a FormRequest class instead of the general Request class, you don't need to call "$request->validated()" to trigger validation. Laravel automatically handles the validation process when using FormRequest classes.
i hope one day you will teach us more about the difference between policies and guardes,listeners and observers etc.
Will do in the future!!
@avfr Observers are simply listeners for model events. You can't choose to use one or the other.
You also cannot manually fire model events from a controller, since they're internally fired by eloquent.
Hi Dary what extension do you use to see what type of the value needed inside the parameters
ex: $table->string(column: 'extension');
the "column""
putting $guarded=[] (empty array) in the model is same as $fillable=[..all request keys here..] and i think you cant put both of these two variables in the same model
I'm pretty sure you can't because these two properties are used to specify which attributes are mass assignable and which are not, respectively. Well, you technically can, but Laravel will prioritize $guarded and ignore $fillable, which could lead to unexpected behavior in your application.
thank you dary
i have simple question why you sometimes use ->value
and sometimes not
i means in enum
The ->value method is used to retrieve the underlying value of an enum instance. Enums in Laravel are implemented as objects, and ->value allows you to access the actual value stored within the enum rather than the enum object itself!
at 8:45, how your methods are showing key like
$table->string(column: "something")
which extension you are using to show "column" thing?
what is the difference between using foreign or foreignID and which is better?
The main difference between the two methods is that foreignId() is a shorthand method that automatically creates a column with an unsigned big integer data type and adds the foreign key constraint to that column. This can simplify the syntax of creating a foreign key constraint.
What theme, font and spacing are u using? Nice video
Theme: SynthWave 84 (Material)
Font: Monaco
Line height: 1.4
brilliant video 👏
Appreciate it David, especially coming from you!
Why do need $request->validated() in controller since it returns validated data from request? Doesn't validation happen automatically?
That works too, just not a fan of using so many things behind the scenes :)
Quick add on btw; I'm reviewing code how I should do it, not saying that it's the best way, just my way.
Yap, there is no best way to do it. Need to make a choice from many ways for particual situation.
Just was wondering if didn't make a typo, because as i knew $request->validated() returns only validated data from a request and not do validation it self. For validation, i was using $request->validate().
@@codewithdary If I understand correctly validation as a formrequest then the data is always validated behind the scenes. When you use request->validated() then you only return validated data but you don't assign it anywhere. It makes no sense to me to use this method in your example.
Amazing video thanks
Glad you enjoyed it Isaac!
6:22 Locale is pronounced “low-kal” 🙂
Thank you Lewis. Sounds like low-kal-ories 😜
Is there really such a method as `required` on the ColumnDefinition? Never heard of it 🤔
Whoops no, I was a bit mixed-up with another framework, sorry for that!
Hey Dary big fan
Thank you so much Tara
Wery nice👍🫡
Thank you so much Karl