Laravel Collections: 5 Methods with Real Examples

  Рет қаралды 28,670

Laravel Daily

Laravel Daily

Күн бұрын

Пікірлер: 48
@daleryanaldover6545
@daleryanaldover6545 3 жыл бұрын
One thing I realized while learning laravel is that eloquent queries return a collection which means we can use collection methods AFTER getting the result from eloquent query. Been using old php way. Also there is the laravel helpers documentation which is a god send.
@sakhaprasna
@sakhaprasna 2 жыл бұрын
i like it sir so useful and clear on explaination i was confused in my way solving how to use where like with collection, then i found this video many thanks!!! ❤❤❤
@dadditsdonovskiy3145
@dadditsdonovskiy3145 3 жыл бұрын
Thank you very much for such a short and nevertheless clear and comprehensive explanation.
@andresluisvelasquez1747
@andresluisvelasquez1747 Жыл бұрын
Gracias por la info
@SowrenSen
@SowrenSen 3 жыл бұрын
Want Tinkerwell features in PhpStorm? Try Laravel Tinker plugin. Super useful one.
@pavelmgn
@pavelmgn 3 жыл бұрын
First example: return array_map(fn($name) => Str::slug($name), self::PROJECT_TYPES);
@mallesbixie
@mallesbixie 3 жыл бұрын
I love collections, but in this case I'd go for the native solution you posted. untested, but I think even `return array_map([Str::class, 'slug'], self::PROJECT_TYPES); ` will work
@1234matthewjohnson
@1234matthewjohnson 3 жыл бұрын
what are your throughts on when to use map() vs each()? they seem to do a very similar thing.
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Well, not really, map() returns something and each() is just for performing some operations, it may not return anything.
@shethchaitali8012
@shethchaitali8012 3 жыл бұрын
Hello can you tell me which editor did u use and how can i do when i change code at a same tome output showing on right side?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
It's not editor, it's Tinkerwell app, it's not free
@R0b3
@R0b3 Жыл бұрын
What kind of editor are you using, PHPstorm or vscode?
@LaravelDaily
@LaravelDaily Жыл бұрын
Phpstorm
@overLordOrigin
@overLordOrigin 3 жыл бұрын
thanks
@bsen2267
@bsen2267 3 жыл бұрын
Hey @Laravel Daily, do you think it's worth learning VIM ?
@GergelyCsermely
@GergelyCsermely 3 жыл бұрын
Thanks!
@bagusk_awan
@bagusk_awan 3 жыл бұрын
i have a question, what's the difference between $collection->mapWithKeys(...) and $collection->transform(...) ?
@thanakornboy1129
@thanakornboy1129 3 жыл бұрын
6:20 I think all Str::contain() run although $query contains in title, right?
@Remls
@Remls 3 жыл бұрын
.
@qudratxojamusayev6785
@qudratxojamusayev6785 3 жыл бұрын
Great video. I just wanted to ask if it is a good practice to filter things with php instead of using database queries
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Good catch. Usually, it's a bad practice, in that example of the video it kinda makes sense because filtering is quite complex with lowercase transformation, so for the same to happen in the database queries, you would probably need to use raw MySQL methods.
@ward7576
@ward7576 3 жыл бұрын
Always better to go with DB filtering. For that you run one query and hydrate models once (ideally). When you return date from DB and filter it on php, you are hydrating a lot of data where a chunk of it will be just thrown away..since filtering. Not as efficient. It would either way be a good practice to learn some more mysql as you go and optimize things ;)
@josuebarros-desenvolvedorw2490
@josuebarros-desenvolvedorw2490 3 жыл бұрын
How can we paginate a HTTP response data? Example: Requesting to a Real Estate listing and paginate the 500 results in groups of 50
@LaravelDaily
@LaravelDaily 3 жыл бұрын
It depends on the structure of how those listings are presented to you. So it's very individual, I can't answer in a comment.
@josuebarros-desenvolvedorw2490
@josuebarros-desenvolvedorw2490 3 жыл бұрын
@@LaravelDaily it is returning as a collection
@developerdiwakar
@developerdiwakar 3 жыл бұрын
Hi Povilas, I have a question. How can we sort collection after concat with pagination? #laravel8
@LaravelDaily
@LaravelDaily 3 жыл бұрын
It needs a specific example, I can't answer with just this short description.
@developerdiwakar
@developerdiwakar 3 жыл бұрын
@@LaravelDaily Okay. Suppose we have two collections $biddings = Bidding::with('user')->paginate(10); and $evaluations = Evaluation::with('user')->paginate(10); then I do this $offers = $evaluations->setCollection( $evaluations->concat($biddings)->sortByDesc('created_at')->values() ); It sets the pagination as well as concatenation but failed to sort the whole collection by created_at in desc order. I want the sorting here.
@afestacincome2224
@afestacincome2224 3 жыл бұрын
Do you have a tutorial on how to send post to Twitter
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Here are a few examples from my Laravel Examples: laravelexamples.com/tag/twitter
@TahirBhai
@TahirBhai 3 жыл бұрын
Thank you for your regular helpful videos, can we expect a video from your channel about mysql database shards in laravel project. I am looking into this now a days but there is no good practical example over there.
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Not in plans, sharding is a niche topic, too niche. I'm focused on broader topics.
@TahirBhai
@TahirBhai 3 жыл бұрын
@@LaravelDaily Thank you :) if you can recommend me some readings or video material about this. Eagerly looking for it.
@cardboarddignity
@cardboarddignity 2 жыл бұрын
This collect()->...->toArray() is pretty performance unfriendly and is kinda slow. If you have and array and want the same array at the end, it's better to use php native methods, like array_map and array_filter. These have the same exact purpose, just avoiding the heavy collect() method
@Voltra_
@Voltra_ 3 жыл бұрын
I'd recommend to use cursor instead of get if you plan to use multiple methods afterwards
@renwar
@renwar 3 жыл бұрын
why?
@Voltra_
@Voltra_ 3 жыл бұрын
@@renwar It returns a lazy collection instead which allows for lazy evaluation instead of eager evaluation (one for loop instead of n for loops)
@yuliarahma1300
@yuliarahma1300 3 жыл бұрын
can you gave us tutorial or concept about otp using telegram, and fresh laravel jetstream, thanks.
@LaravelDaily
@LaravelDaily 3 жыл бұрын
I don't work with OTP and Telegram.
@yuliarahma1300
@yuliarahma1300 3 жыл бұрын
@@LaravelDaily can you at least give us an example or which file to modify to change two factor auth from email to telegram? is it possible right?
@rishikantsrivastava2444
@rishikantsrivastava2444 3 жыл бұрын
Hi Povilas, Thanks for your wonderful support to Laravel community and people like me. but kindly clear this as well, two cases are there, Case 1: if(statement1||statement2||statement3) { return; } Case 2: if(statement1) { return; } if(statement2) { return; } if(statement3) { return; } Case 1 : everytime, all three statement will be executed, Case 2: Not All conditions will be executed.it might be 1, 1-2, or 1-2-3 So which is better?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
In theory, separate if statements are better for performance, you're right, only one would be executed. But if it's just a simple comparison without any DB query or other expensive operation, then performance difference would be 0.0001s and code will be longer for no big reason.
@devKazuto
@devKazuto 3 жыл бұрын
I don't like chained conditions. Yes, it's shorter but it's less readable. I'd much rather have code that is easier to read than having that requires to think what could happen in that chain, especially if you have chains like "|| ($a && $b) || (!$c || $d)" and so on.
@travholt
@travholt 3 жыл бұрын
I agree. The multiple if statements read almost like English and it makes the logic very easy to understand at a quick glance.
Laravel Contracts and PHP Interfaces: Explained with Two Examples
10:10
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 62 МЛН
One day.. 🙌
00:33
Celine Dept
Рет қаралды 62 МЛН
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 40 МЛН
In This House, We’re Angry When Government Fails
1:08:47
New York Times Podcasts
Рет қаралды 49 М.
Exceptions in Laravel: Why/How to Use and Create Your Own
12:18
Laravel Daily
Рет қаралды 88 М.
Faster Eloquent: Avoid Accessors with Foreach
9:35
Laravel Daily
Рет қаралды 54 М.
Eloquent Collection Magic - Map vs Each Methods #4
7:17
Bitfumes
Рет қаралды 4,9 М.
Laravel Eloquent: Deeper Relationships with One Query
10:37
Laravel Daily
Рет қаралды 144 М.
Laravel Collections vs Arrays: Performance Test
6:45
Laravel Daily
Рет қаралды 26 М.
9 Tips for Shorter Laravel Code
10:16
Laravel Daily
Рет қаралды 62 М.
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 62 МЛН