php - Removing id from foreach if user_type is not 5 -
i have page categories in foreach loop, wish remove 1 if user not have user_type of 5, eg
the below simple laravel foreach
@foreach ($category $cat) {{$cat->id}} {{$cat->title}} on.. @endforeach
the category id wish remove 1 unless user_type 5
$user->userprofile->user_type 5
i think have come not sure if the.. best way of doing it.
@foreach ($category $cat) @if($user->userprofile->user_type !=5) @if($cat->id != 1) {{$cat->id}} {{$cat->title}} @endif @else {{$cat->id}} {{$cat->title}} @endif @endforeach
propably in controller have
controller
public function whatever() { $category = categorie::all(); if(auth::user()->userprofile->user_type !=5) { $category->forget('put right key here'); // dd $category collection right key } return view('hodor')->with('category',$category); // simple loop in iew }