Answer the question
In order to leave comments, you need to log in
Display a list sorted by model?
Hello.
I just can’t figure out how to display the sorted values in the form without a large number of queries to the database
Model
-rule
-rule
-rule
Model#2
-rule
Rules (`rule`, `modelNameString`)
following query [
{
'rule' => 'news-create',
'model' => 'News'
},
{
'rule' => 'news-update',
'model' => 'News'
},
{
'rule' => 'comment-create',
'model' => 'Comment'
}
]
News
-news-create
-news-update
Comment
-comment-create
Answer the question
In order to leave comments, you need to log in
Decided for those who are interested.
I used the laravel functionality, but you can do it with regular arrays.
$initial = $model->get();
$transformed = [];
$initial->transform(function ($item, $key) use (&$transformed) {
if(!isset($transformed[$item->model]){
$transformed[$item] = collect();
}
$transformed->push($item);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question