No video

Laravel: how to deal with THICC models

  Рет қаралды 2,480

Przemysław Przyłucki

Przemysław Przyłucki

Жыл бұрын

Hi guys!
In this video I'll show you how to simplify a model, and transform it from FAT to FIT.
Disclaimer: I had to put that thumbnail in, I'm sorry.
More content: saaslaravel.com
Personal website: przemyslawprzy...
Contact: contact@saaslaravel.com

Пікірлер: 16
@verard0
@verard0 Жыл бұрын
That is an amazing content! I'm enjoying a lot your videos! And really liked the one about Service Pattern and DTOs! Keep up the great work buddy!
@saaslaravel
@saaslaravel Жыл бұрын
Thanks so much Valentim! Is there a specific concept that you'd like me to cover next?
@verard0
@verard0 Жыл бұрын
@@saaslaravel Yeah! Maybe you can talk a little bit about repositories explaining why are they used for, how they can fit into the projects or get deeper into laravel environment, for example talk about events, observers, bindings, singletons... or even approaches to eloquent versus query builder....
@karlson2804
@karlson2804 Жыл бұрын
It is incredible, need more!
@GergelyCsermely
@GergelyCsermely Жыл бұрын
Thanks
@numenor21
@numenor21 Жыл бұрын
very clean that code at the end.. thanks mr
@kevinwakhisi7001
@kevinwakhisi7001 Жыл бұрын
That's awesome. Learned new things today before I sleep
@saaslaravel
@saaslaravel Жыл бұрын
Glad you enjoyed it!
@JeremyStreich
@JeremyStreich Жыл бұрын
* Long file does not necessarily mean bad, that is an all too common a fallacy. * I really disagree with removing fillable on the user model because it has the password hash, remember token, and possibly API tokens and the like. Yes, if everywhere is using validated you have some protection, but the model shouldn't trust that the controller is always doing the right thing every single time. Changes happen, and all devs (especially new ones) make mistakes. You should always error on the side of security. * Using an observer shortens the user model file, but doesn't really decrease LOC or improve readability -- just moves it. So, that is really 7 of one ceiling of half a baker's dozen of the other. That's personal preference, not "better code." * Agree with using enum for roles (or moving roles to database to make them more extensible). * Not sure I agree with moving the role functions to the role enum as it makes future possible changes that might happen harder, for instance at a later users may have more than one role and it would be easier to modify for that keeping the functions in the user model. Or for instance roles could become a model relationship in the future, and thus require those function move back to user. Keeping the function in the model instead of the enum makes better sense. * Agree with you on the user status enum and moving the color function. * Agree on using Laravel accessors and mutators. * I don't agree with creating the forUser function in the enum, that isn't the enum's responsibility it is the user model's. * I'm not sure I agree with moving the query builder functions to another object or not -- I like being able to look at the user model to know what I can do with it, without having to hunt down the custom builder class. Especially because the builder isn't reusable for any other class except users. The enums created could, in theory, be reused by other classes, but the userBuilder really can't because they depend on the user's fields specifically. While, this one I think is matter of taste, moving them to the builder geels like lowering cohesion and rising coupling to move them off to another class -- the opposite of what we want in our object structure.
@PalEmilLucian
@PalEmilLucian Жыл бұрын
Instead of observers I use traits, like ... trait NewTrait { ... public static function bootNewTrait() { ... static::saving(function ($model) { .. } } }. The model's boot() method will use bootNewTrait(). Also scopes could be traits (active, disabled etc are found across many tables and can be reused). Thanks for the input!
@JeremyStreich
@JeremyStreich Жыл бұрын
@@PalEmilLucian Traits are great for reuse. That is, you don't want to add "notifiable" code to both users and groups, so they both would use the "notifiable" trait. Meanwhile, sticking the query builder objects in a trait means hiding the functions away. You're still decreasing cohesiveness and increasing coupling.... It's generally bad design -- unless reuse across models is not possible but expected.
@DougLopes
@DougLopes Жыл бұрын
Besides the comments removed 🤣🤣, i loved the way you organized the logic.
@saaslaravel
@saaslaravel Жыл бұрын
I mean I don't hate comments - I just don't like the default ones! After so many years we all know what $hidden does :D
@victordepta4069
@victordepta4069 Жыл бұрын
Fajne fajne ❤
@vladislavkim3355
@vladislavkim3355 Жыл бұрын
replace fillable to guarded is absolute shit idea in my mind, just because the fillable property also gives ur info about columns in table without checking migrations
@saaslaravel
@saaslaravel Жыл бұрын
There are functions you can call for that :) Also some ide helper magic and you're golden
Refactoring real-world Laravel app. Who wrote THIS CODE?!
28:02
Przemysław Przyłucki
Рет қаралды 10 М.
Are VALUE OBJECTS secretly overpowered?!
13:44
Przemysław Przyłucki
Рет қаралды 3,4 М.
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 32 МЛН
Pool Bed Prank By My Grandpa 😂 #funny
00:47
SKITS
Рет қаралды 18 МЛН
Why Is He Unhappy…?
00:26
Alan Chikin Chow
Рет қаралды 95 МЛН
Советы на всё лето 4 @postworkllc
00:23
История одного вокалиста
Рет қаралды 5 МЛН
Laravel: Repository Pattern in practice
27:13
Przemysław Przyłucki
Рет қаралды 11 М.
Laravel: 1,000,000 webhooks/minute?! Ingest webhooks like a PRO
20:51
Przemysław Przyłucki
Рет қаралды 4,4 М.
Livewire vs. Inertia
11:05
Laravel Magazine
Рет қаралды 3,8 М.
Testing has never been THIS EASY [Free course: Great Laravel Apps #3]
22:47
Przemysław Przyłucki
Рет қаралды 2,5 М.
Laravel: WAY BETTER Exception handling in 10 minutes
14:27
Przemysław Przyłucki
Рет қаралды 4,2 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 562 М.
WOW! Laravel's pipeline pattern is AWESOME
20:39
Przemysław Przyłucki
Рет қаралды 12 М.
Making A Billion-Year Lego Clock
13:11
Brick Technology
Рет қаралды 7 МЛН
Laravel: Simple Strategy Pattern
7:12
Przemysław Przyłucki
Рет қаралды 3,2 М.
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 32 МЛН