如何显示按特定类别过滤的记录

How to show records filtered by specific category

如何使用 if 在我的 blade 文件中列出特定类别的音乐家?

如果您只想在视图中列出或显示特定类别的音乐家,那么您可以在控制器方法中过滤音乐家,然后将过滤后的数据发送到视图

public function group()
{
    return view('pages.group', [
        'musicians' => Musician::where('category_id', 10)->get()
    ]);
}

然后在blade视图中

@foreach($musicians as $musician)
    <p>{{ $musician->musician_name }} {{ $musician->musician_surname }}</p>
@endforeach

it works thanks. but if I wanted to print on one line the musicians of the category with id 10 and on another line the musicians of the category with id 40? always on the same blade file

public function group()
{
    return view('musicians', [
        'categories' => Musician::get()->groupBy(function($item) {
            return $item->category_id;
        })
    ]);
}
@foreach($categories as $catetory)
    @foreach($category as $key => $musician)
        <p>{{ $musician->musician_name }} {{ $musician->musician_surname }}</p>
    @endforeach
@endforeach