Skip to content
Advertisement

Is it possible to use a passed parameter several times in Laravel?

I am new to Laravel and I’m developing an application. I’m trying to fetch the data from a database, which works fine, and print them on a screen using a passed parameter to blade, this also works fine. However, when I want to use the same passed parameter for several times, I get the following error:

Attempt to read property “id” on bool

Here are the code snippets that I use on the application:

class ProfileController extends Controller
{
    function getUserInfo(){
        $user_id = Auth::id();
        $beverage_list = Beverages::get();
        $places = Place::get();
         return view('profile',['list'=> $beverage_list, "places"=>$places]);

     }
}

I want to use the following part twice on blade.php. There is no problem when I use it once though.

<div class="col">
     <select name="beverage9" id="beverage9">
         <option value="">Choose your 9 o'clock beverage</option>
               @foreach($list as $list)
                 <option value="{{$list->id}}">{{$list->beverage_name}}</option>
                @endforeach
      </select>

</div>

Thank you for your help 🙂

Advertisement

Answer

Return this way,

return view('profile',['lists'=> $beverage_list, "places"=>$places]);

Then in the view,

@foreach($lists as $list)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement