Excellent approach would love to use in Laravel, but as often I'm working on different languages and frameworks i prefer classic way for welcoming juniors as well to take over for the changes etc
When chaining more than one method, I recommend transforming it into a LazyCollection first to reduce time complexity (*Model::query()->cursor()* for DB, *collect()->lazy()* for the rest)
In my humble opinion prefer the pure php method for simple tasks 'cause any call to Laravel's commands implies more code to be executed for the server. I'm most for a compromise between code easy to read and performance. But, another time, this is simply my humble opinion.
"more code to be executed" - do you have any time measurements for that? Cause I think it's a myth, there's almost no difference in performance from what I've tested.
@@LaravelDaily Nope, I haven't any measurement, only a little math assertion support my preference, that's: 1 > 0 . More and more, not only performance could be affected IMO, RAM resources could be involved also. But I insist this is my humble opinion about that. Thanks for your time and useful teaching work, sincerely.
In this instance this looks less readable than the original for each. I love using collections and chaining with maps etc but I think in this example the regular php method would be preferable.
@@LaravelDaily yup, recently i implemented the reporting feature which is contain a lot of data. I figured out the colection filter is very slow instead of get all data at the begining and make them as array (index by foreign keys)
You can use nested hasMany() in model. Example: /** * Get all of the comments for the Comment * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function comments(): HasMany { return $this->hasMany(Comment::class); } /** * Get all of the children for Comments * * @return mixed */ public function childrenComments() { return $this->comments()->with('childrenComments'); }
@@wahyu_pratamabwi bro I know all these things but look there will be 3 forms one for the main comment one for the reply and one for the edit comment I have already applied the 1st 2 steps but idk how to edit the comment if you want i can show the source code
Excellent approach would love to use in Laravel, but as often I'm working on different languages and frameworks i prefer classic way for welcoming juniors as well to take over for the changes etc
I came from JS world so it's really worth learning Collection :D
Keep going amazing videos
in therms of performances which one is the best? With collection it's more elegant and readable, but sounds too many loops on it, isnt it?
I will shoot a demo about it. The difference in performance is almost non existent.
@@LaravelDaily i think this should be the focus. Thanks
I prefer to use the collection in Laravel.
Como hago para que en un $data = collect()->put('name', 'jesus' ); pueda hacer $data->name;
When chaining more than one method, I recommend transforming it into a LazyCollection first to reduce time complexity (*Model::query()->cursor()* for DB, *collect()->lazy()* for the rest)
Thanks, I didn't know we had things like this in PHP / Laravel.
Great example, not so different from Stream API and related methods (map, filter, collect) we see in Java
In my humble opinion prefer the pure php method for simple tasks 'cause any call to Laravel's commands implies more code to be executed for the server. I'm most for a compromise between code easy to read and performance. But, another time, this is simply my humble opinion.
"more code to be executed" - do you have any time measurements for that? Cause I think it's a myth, there's almost no difference in performance from what I've tested.
@@LaravelDaily Nope, I haven't any measurement, only a little math assertion support my preference, that's: 1 > 0 . More and more, not only performance could be affected IMO, RAM resources could be involved also. But I insist this is my humble opinion about that. Thanks for your time and useful teaching work, sincerely.
hey;
thanks for video ıt's a helpful video but I have a question how to define two dimensional array? ( $arr[][] ) thanks for answer
In this instance this looks less readable than the original for each. I love using collections and chaining with maps etc but I think in this example the regular php method would be preferable.
Thanks
Whenever i see the collection methods in laravel docs i always think why php array methods are not as simple as this.
as someone who also works with javascript, I am used to array method chaining.
love it!
PLS make full course about Laravel collection
Working on it for June/July.
I believe sometime Laravel collection is quite slow than array. E.g: Collection filters..
Do you have any real tests with measurements?
@@LaravelDaily yup, recently i implemented the reporting feature which is contain a lot of data. I figured out the colection filter is very slow instead of get all data at the begining and make them as array (index by foreign keys)
hopefully I can give you an example later.
Yes without certain example I can't comment. In my tests, I didn't see much difference.
How to make a comment reply system in livewire with recursion? This concept is seriously so hard to understand!
You can use nested hasMany() in model. Example:
/**
* Get all of the comments for the Comment
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments(): HasMany
{
return $this->hasMany(Comment::class);
}
/**
* Get all of the children for Comments
*
* @return mixed
*/
public function childrenComments()
{
return $this->comments()->with('childrenComments');
}
@@wahyu_pratamabwi yeah I have already done all those things but Idk how to edit comments or replies in real time
@@darkestbrush604 just use the comment id to edit
@@wahyu_pratamabwi bro I know all these things but look there will be 3 forms one for the main comment one for the reply and one for the edit comment I have already applied the 1st 2 steps but idk how to edit the comment if you want i can show the source code
@@darkestbrush604 sure, can I make a pull request to your github repository?