Livewire Code Review: Likeable Component - 10 Improvements

  Рет қаралды 6,454

Laravel Daily

Laravel Daily

Күн бұрын

This is a code review of a Livewire component, which is actually optimization of the PHP class. Will you join me?
00:00 Introducing Component
01:31 Code Overview
03:01 Undefined Class Properties
03:51 Dynamic Class Names
05:45 Unnecessary Variable/Query
07:30 Formatting the Code
07:47 Config Default Values
09:15 Public or Private Methods
10:40 Wait, THAT many DB Queries??
15:17 Remove Duplicate Methods
15:57 Eloquent create() vs save()
17:07 Remove Even More Methods
Related links:
- Laravel and PHP Try-Catch: Exceptions VS Errors? • Laravel and PHP Try-Ca...
- My Course "Practical Laravel Livewire from Scratch" laraveldaily.teachable.com/p/...
- My Livewire Kit: Set of Components livewirekit.com/
- - - - -
Support the channel by checking out our products:
- Enroll in my Laravel courses: laraveldaily.teachable.com
- Try our Laravel QuickAdminPanel: bit.ly/quickadminpanel
- Purchase my Livewire Kit: livewirekit.com
- View Laravel Code Examples: laravelexamples.com
- Subscribe to my weekly newsletter: bit.ly/laravel-newsletter

Пікірлер: 18
@daleryanaldover6545
@daleryanaldover6545 2 жыл бұрын
I found out about using dynamic class names by source diving the Model class. Another cool thing you can do is using dynamic variable names which is kinda weird but helps if you found yourself in a scenario where dynamic variables would be helpful.
@ilhamfajriumar9085
@ilhamfajriumar9085 2 жыл бұрын
I think setting up the initial like or dislike is the best way to reduce the query even more, that's the way i did it in some of my project
@maximusmitchell1229
@maximusmitchell1229 2 жыл бұрын
How do you mean?
@ilhamfajriumar9085
@ilhamfajriumar9085 2 жыл бұрын
When the likeable component loading it's actually getting the like status inside mount. If there are multiple likeable component loaded the query will run as much as the loaded components. Instead doing that, passing the like status from parent component, which can be fetched using eager loading will reduce the query thats being called
@rahmanramsi
@rahmanramsi 2 жыл бұрын
I prefer to pass the model itself instead only the classname and id, so i dont need to query to database to get the data, cuz its already there. So it should becomes like this `@livewire('likeable', ['model' => $comment])
@nabilhassen1944
@nabilhassen1944 2 жыл бұрын
its not secure to do so. anyone can open up the devtools and all of your model data will be available there.
@rahmanramsi
@rahmanramsi 2 жыл бұрын
@@nabilhassen1944 didn't know that, thanks for the info.
@rahmanramsi
@rahmanramsi 2 жыл бұрын
@@nabilhassen1944 btw where i can find that model data in devtool?
@usanzadunje
@usanzadunje 2 жыл бұрын
14:50 Could we just query all the likes(that we need of course) from the parent component and then pass them to each button component. This would result in only one query and remove query to db from component itself?
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Yes, probably, but that kinda defeats the purpose of component that could be reused anywhere.
@krishnanarasimha1243
@krishnanarasimha1243 2 жыл бұрын
I missed the yesterday 48 hour videos :(
@kingstalker
@kingstalker 2 жыл бұрын
King Stalker 0 seconds ago Is there anyway to make the blade syntaxes autocomplete for you for the live wire things also can it not look so white I see spatie permissions blade does the same thing for example I say @role(autocomete your role ) and looks like a normal blade syntax I hope I make sense
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Some Blade support comes from PhpStorm, some can be provided by Laravel Idea package for PhpStorm, but I don't think they cover specific packages like Spatie Permissions or others.
@Ghost-hz2dy
@Ghost-hz2dy 2 жыл бұрын
In the next video "code review" i want to share my github repository and review it. How i can send you email ?
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Currently I have 5 reviews in queue, so realistically I can do only in November. You can email me povilas@laraveldaily.com and invite me to GitHub, username povilaskorop
@abdulrehmandar8541
@abdulrehmandar8541 2 жыл бұрын
I have a question. 1. livewire always render full page on request. Is there any way to render only specific div. without using wire:ignore. 2. I have a bootstrap form wizard when ever make some request the wizard steps become inactive or may go to first step if we are on other step. currently i'm handling it making the steps dynamic to check which step is active or not it works but still flicker. do you have any idea, advice to manage state. Thank you.
@LaravelDaily
@LaravelDaily 2 жыл бұрын
1. No, unless you split them into separate components 2. Can't answer in a comment, needs debugging
@ahmednisar9960
@ahmednisar9960 2 жыл бұрын
make one laravel project from scratch....not like this
Junior Code Review: 13 Tips from Cryptocracy Project
15:01
Laravel Daily
Рет қаралды 11 М.
5 Livewire Examples: Code Review of Mealing Project
20:56
Laravel Daily
Рет қаралды 7 М.
OMG🤪 #tiktok #shorts #potapova_blog
00:50
Potapova_blog
Рет қаралды 18 МЛН
MEGA BOXES ARE BACK!!!
08:53
Brawl Stars
Рет қаралды 35 МЛН
Каха ограбил банк
01:00
К-Media
Рет қаралды 11 МЛН
Laravel Controller Code: Move to Model, Service, Action or Job?
12:51
Laravel Daily
Рет қаралды 104 М.
Eloquent Soft Deletes: Things You May Not Know
10:57
Laravel Daily
Рет қаралды 20 М.
What is JWT? JSON Web Tokens Explained (Java Brains)
14:53
Java Brains
Рет қаралды 1 МЛН
18 Laravel/PHP Tips in 10 Minutes: June 2024
10:41
Laravel Daily
Рет қаралды 7 М.
Faster Eloquent: Avoid Accessors with Foreach
9:35
Laravel Daily
Рет қаралды 52 М.
Like Button | Build Blog with Laravel, Livewire & Filament #10
29:19
Unboxing MEGATRON 40th Anniversary Limited Edition Robot by Robosen
1:00
Popping green grap jelly!- got these in Japan
0:16
Priya kumari
Рет қаралды 23 МЛН
Survival skills: A great idea with duct tape #survival #lifehacks #camping
0:27
Skateboarding Down the Steps
0:11
Ryan's World
Рет қаралды 36 МЛН