Organizing data with Laravel Collections
HTML-код
- Опубликовано: 13 июл 2024
- In this 32 minute video, I'll show you 12 examples using Laravel Collections that you can use to organize, sort, and filter your large or complex data sets.
You'll learn how to:
- Set up a basic Laravel 8 project
- Use Laravel's HTTP library to pull in JSON from Reddit
- Filter and organize a large data set with a variety of collections
- Maximize code efficiency and readability
- 0:00 Intro
- 00:34 Project Setup
- 06:06 Filter Method
- 09:02 Pluck Method
- 11:00 Contains Method
- 13:28 GroupBy Method
- 17:18 SortBy Method
- 19:06 Partition Method
- 22:40 Reject Method
- 24:16 WhereIn Method
- 25:38 Chunk Method
- 27:22 Count Method
- 28:30 First Method
- 30:22 Tap Method
- 32:18 Conclusion
Follow me on Twitter! / aschmelyun Наука
Your tuts are of great style and pace and are very helpful for me as a relative Laravel newbie. Thank you.
Fantastic! Best tutorial on collections I’ve seen
This is an amazing tutorial. I've watched several tuts on Collections but this stands out for me. Awesome Tut, Awesome Example. Awesome Pace.
Thank you Andrew
So you got here sir
This tutorial saved me
@@oladayoagbolade3676 yes o 😃
This channel needs more views and more videos. Thanks.
Thank you! I'm working on getting there, haha.
@@aschmelyun I know, I bet you have a real world job and this tuts are an extra, you teach so well, I bet if you make complete series you will get tons of views.
Very cool. Thanks for sharing!
Great quality content
Video on your phpstorm setup
Great info.
Great Work
thank u
go ahead
Love this wow
Nice thank you
thanks tons...
thanks for sharing
amazing
I hope you can make videos related to laravel CI/CD
Can you make an example with foreign tables queries on livewire? I have an example that I'm struggling with
Which editor you are using and which plugins ?
Phpstorm
Why do you initialize a PRIVATE property through the controller CONSTRUCTOR for the index method?
Because the constructor is always called to initialize the controller class. That way, he doesnt have to initialize it on all the other methods.
So... if I get some Real Estate data coming from a external api (json), convert into a Laravel Collection I can paginate the results with pagination method?
Good question. Did you hack this? Been struggling with the same. After converting Odata to collection how do you paginate without first saving to db table
@@stephenmcatieno3849 hmmm, I don't quite remember because its been a while... since I hit apis with ReactJS now, I can get the results and modify in any format using javascript functions
Some objects in the collection don't have the post_hint key anymore which causes it to return an error: Undefined array key "post_hint"
Ah, thanks for letting me know!
@@aschmelyun Please can you help me / us with a solution as to how to get around the problem Undefined array key "post_hint" with collections filter method. I am struggling to find a solution for days now.
Please start laravel project
I am not seeing your result. From the filter method I get ErrorException undefined array key "post_hint". I am using Laravel 10?
Hi there. I found the solution - I think: public function filter()
{
$posts = $this->posts->filter(function($post, $key) {
if( empty($post['data']['post_hint'])) {
return false;
}
return \Illuminate\Support\Str::contains( $post['data']['url'], 'i.redd.it');
});
what is dcr?
He uses Docker. so it's a docker specific command not Laravel. Can't remember, he's talked about it before.
Okay, better tell us all about your keyboard now mister.
too fast
Hi here is the work I put in for pluck. Seems to be working. 1. declare $images at top of controller then public function pluck()
{
$images = $this->posts->filter(function($post, $key) {
if( empty($post['data']['post_hint'])) {
return false;
}
return \Illuminate\Support\Str::contains( $post['data']['url'], 'i.redd.it');
})
->pluck('data.url')
->all();
return view('collections.pluck' , [
'images' => $images
]);
}
2. In pluck.blade.php @foreach($images as $image) blabla blabla@endforeach