Laravel API+Vue Code Review: 12 Things I've Noticed

  Рет қаралды 17,338

Laravel Daily

Laravel Daily

Күн бұрын

Пікірлер: 45
@mrengineer4076
@mrengineer4076 3 жыл бұрын
19:10 auth()-user() Object - use $request->user() as it's already injected to controller methods - using auth()->user() three times means instantiating Auth three times. Using variable makes more sense here.
@ВладиславГайсюк-ъ7ц
@ВладиславГайсюк-ъ7ц 2 жыл бұрын
also that variable is just a ref to a User Object, so calling 3 times auth()->user() jus increases call stack and returning the same object 3 times :/ Additional var will be just a link in memory :)
@martomystery
@martomystery 2 жыл бұрын
@@ВладиславГайсюк-ъ7ц does this mean you don't agree with using $request()->user() 3 times either?
@ВладиславГайсюк-ъ7ц
@ВладиславГайсюк-ъ7ц 2 жыл бұрын
@@martomystery as far as I know - $request->user() just returns User ref that was injected by constructor while building request object. auth()->user() is always calling Gate - resolving user. But I can be wrong, and $request->user() does the same :D
@ajithlal1688
@ajithlal1688 3 жыл бұрын
As always thank you for the video. Two things I have to mention. First one will be small information. 1. Its an arabic website (because you said that you don't know the language). 2. Using of a variable instead of calling same function repeatedly in many places. You refactored the code $user = auth()->user(); to just auth()->user() in 3 places. So if the developer want some other functions in the future he have to change that function in all the 3 places. In this kind of situation, I will do like the developer did. So I have update the function in only one place. I will go with your suggestion if I have to call the auth()->user() in only one place/code block. Just sharing the thoughts.
@J87NL
@J87NL 3 жыл бұрын
Too bad the application isn’t translated, that’s the minimum I would have done before asking someone to review something on KZbin. Thanks again for sharing your content Povilas!
@alila3883
@alila3883 3 жыл бұрын
Now, It's in English and Arabic languages github.com/alijumaan/Laravel-Vue-SPA
@J87NL
@J87NL 3 жыл бұрын
@@alila3883 Nice 👍 One small thing though: the text “English” in your dropdown shouldn’t be translated since non-Arabic readers won’t find the button otherwise 😂
@alila3883
@alila3883 3 жыл бұрын
@@J87NL 🤣🤣
@mrengineer4076
@mrengineer4076 3 жыл бұрын
15:49 Eloquent: Don't Load Too Much Data - Extinguisher::distinct('type')->pluck... is correct Eloquent way to get distinct values
@biscaynestudd
@biscaynestudd 3 жыл бұрын
how about Extinguisher::distinct()->pluck('type') ?? wouldn't that work also? is there a difference?
@mrengineer4076
@mrengineer4076 3 жыл бұрын
​@@biscaynestudd you're right, distinct()->pluck('type') works perfectly fine here.
@AbrarAhmad-mz8vl
@AbrarAhmad-mz8vl 3 жыл бұрын
Tons of learnings here
@ricko13
@ricko13 3 жыл бұрын
I had no clue about accessors and mutators! thanks
@renwar
@renwar 3 жыл бұрын
in 18:00 where he used save() instead of create() is because the table might not have timestamp columns? which produce errors.
@SinghatehAlagie
@SinghatehAlagie 3 жыл бұрын
yap that can be another case as well
@darkmode404
@darkmode404 3 жыл бұрын
@@SinghatehAlagie create can also have no timestamps if the model has timestamps = false
@kartiksprajapati6006
@kartiksprajapati6006 3 жыл бұрын
I think updatePassword method can be more refactored in the last part of video by creating a new rule for password comparing and moving the code to the new validation rule...
@aleksandarstevanovic5854
@aleksandarstevanovic5854 3 жыл бұрын
what do you guys think about the response layer to be added to this? in controller to massage the data you want but at the and you return new UserShowResponse($user) for example, and in it you put the things you think "i need this in controller but i dont want it to have this junk" like... idk format_number(), $user->map(), $user->avatar->getFullUrl() or similar.... at the end controller is much cleaner but there are a lot of response classes
@ejaysjaaki
@ejaysjaaki 3 жыл бұрын
There are many tutorials that explain how to use Laravel and Vue/React in the same project with Passport/Sanctum. Does anyone know a good tutorial where the Api and front end(framework) are divided? preferably a tutorial with Laravel 8 - passport authentication and as front end Vue/React. Thx!
@darkmode404
@darkmode404 3 жыл бұрын
search decoupled laravel and vue
@raimonds.L
@raimonds.L 3 жыл бұрын
I'm currently in development of VUE SPA + LARAVEL API - two separate projects (frontend on port 80 and backend on port 8000) - what are the downsides and upsides vs a single project? Do you still provide auth bearer?
@ArjonJasonCastro
@ArjonJasonCastro 3 жыл бұрын
Thank you for this great video! Do you also have a review comparing Laravel Sanctum, Passport and Tymon-JWT?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
No, I don't have direct comparison. But, by default, I recommend Sanctum to everyone now, it's the most simple.
@ArjonJasonCastro
@ArjonJasonCastro 3 жыл бұрын
@@LaravelDaily I haven't tried sanctum yet. Currently I am still using tymons JWT for SPAs. Thanks for the responses!
@NotBeHaris
@NotBeHaris 3 жыл бұрын
Api Resources controller are important for apis are we just returned json data in api. In simple way without creating api resources controller. I hope my today question is relevant to video.
@dauletsailauov3858
@dauletsailauov3858 3 жыл бұрын
Hello may i ask you like a laravel pro developer, what is best way to be guru in laravel and the best place to learning?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Practice, practice, practice. Take projects and learn by practice. Best place to learn is Laracasts, and the official documentation. Also, you may take my courses: laraveldaily.teachable.com
@ryiad2010
@ryiad2010 5 ай бұрын
very helpful
@mohamednabih6036
@mohamednabih6036 3 жыл бұрын
amazing, thanks a lot
@adityakadam2256
@adityakadam2256 3 жыл бұрын
Hey Povilas, your content is always amazing. Just a request for a video, if you haven't done it before and if it's possible. Is it possible to make a video on how to fetch Livewire data like Vue.js with lazy loading, For instance in Vue, you can see the HTML elements first and then the data can be hydrated in these respective components as required. In Livewire this is a bit tedious I guess, is there any straightforward way to do lazy loading in Livewire?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
I haven't seen anything exactly like that in Livewire, to be honest. But, there's a wire:loading where you can show another div while data is loading. It kinda achieves the same experience?
@lucasj.pereira4912
@lucasj.pereira4912 3 жыл бұрын
I believe what you are looking for is Livewire Defer Loading (Cant post links as youtube just deleted another commend I posted here, so google it). There is a official documentation about it.
@adityakadam2256
@adityakadam2256 3 жыл бұрын
Thanks a lot for the reply Povilas and Lucas. Actually wire:loading is more of when you the component is already rendered and actions there after can me done with wire:loading. Thanks Lucas, I can understand, KZbin does that sometimes. I will have a look into it. One work around I tried was something like this. in User.php (component.php) public function mount($ids){ $this->ids = $ids; } public function fetchUsers(){ $this->users = User::whereIn('id', $this->ids)->get(); } public function render(){ return view('user.blade.php') } in user.blade.php (component.blade.php) window.addEventListener('DOMContentLoaded', ()=>{ @this.fetchUsers() } )
@AjayKumar-mi2mr
@AjayKumar-mi2mr 3 жыл бұрын
Sir can you tell me how do I push my Laravel app to GitHub with database & one more thing is how can I connect with you to ask something about laravel
@mohamedel-damarawy6595
@mohamedel-damarawy6595 3 жыл бұрын
There’s nothing special for laravel when it comes to pushing a project to GitHub, maybe you need go through a quick Git tutorial
@justtestingmycurrentskills747
@justtestingmycurrentskills747 3 жыл бұрын
What is your opinion on using JWT instead of passport and sanctum?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
It's a personal preference and habit. JWT sounds to me like "the old way" of doing things, which existed before both Passport/Sanctum. So if it works for you, it's cool, but for those who started with Sanctum, I guess they stay with Sanctum. Same as Passport.
@alexrusin
@alexrusin 3 жыл бұрын
JWT is actually a token format (an open standard). Passport and Sanctum could have used JWT tokens instead of simple tokens. Some implementations of Oaut 2.0 will actually use JWT as a bearer token. JWT is usefull when you don't want to record a token in the database. Imagine a Laravel backend for a mobile app. If the app gets really popular you could end up with millions of tokens in the database. Searching and maintaining those tokens can be a lot of work. So, instead of attaching token to a user and saving it in DB, you record user's info (usually user id) in the token and send it back to your mobile app. When app uses this token to authenticate, your backend will decrypt it, make sure it is not expired and will find a user in DB from the user id passed in the token.
@darkmode404
@darkmode404 3 жыл бұрын
im actually interested in this topic as well
@thecongvu6383
@thecongvu6383 3 жыл бұрын
Thank you!!!
@gram_o_phone
@gram_o_phone 3 жыл бұрын
Sidetrack but WOW, it must be hard coding ltr and inserting rtl messages...
@Pharaoh-99
@Pharaoh-99 3 жыл бұрын
its arabic :)
@saidbenhmed7884
@saidbenhmed7884 3 жыл бұрын
It's Arabic language Sir
@ShadiMuhammad
@ShadiMuhammad 3 жыл бұрын
It's Arabic Language. 😄
15 Laravel Tips to Work in a Team
23:15
Laravel Daily
Рет қаралды 17 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Laravel Return Types in API Controller: Five Options?
8:15
Laravel Daily
Рет қаралды 3,8 М.
SQLc is the perfect tool for those who don't like ORMs
28:11
Dreams of Code
Рет қаралды 115 М.
Laravel Junior Code Review: Security and Consistency
17:29
Laravel Daily
Рет қаралды 50 М.
You Wouldn't Believe These Developer Interview Mistakes...
9:23
Program With Erik
Рет қаралды 6 М.
DHH discusses SQLite (and Stoicism)
54:00
Aaron Francis
Рет қаралды 105 М.
4 Packages You Need in ANY Laravel Project
8:14
Laravel Daily
Рет қаралды 62 М.
Laravel Security: Top 7 Mistakes Developers Make
11:16
Laravel Daily
Рет қаралды 88 М.
Laravel and 3rd-Party APIs: The PROCESS
11:31
Laravel Daily
Рет қаралды 3 М.
Eloquent Performance: TOP 3 Mistakes Developers Make
7:59
Laravel Daily
Рет қаралды 49 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН