david2000
1 month ago
333
18
General

Invalid argument supplied for foreach() (View:

Posted 1 month ago by david2000

Hello,

I have like error message : Invalid argument supplied for foreach() (View:

For my method index() I have this:

public function index(Request $request)
    {   
    if(\Auth::user()->hasRole('admin')){
         if($request->has('search'))
              $remarks = Remark::orderBy('instruction', 'asc')->where('instruction','like','%'.$request->input('search').'%');
         else
             $remarks = Remark::all();
    }else{
         \Auth::user()->load('remarks');
         $remarks = \Auth::user()->remarks;
    }

    return view('admin.remarks.index', compact('remarks'));
    }

Concerning my index.blade.php I have my loop "for" which is like this:

<th>Instruction</th>
                  <th>Description</th>
                  <th>Date seance</th>
                  <th>Name Candidate</th>
                  <th>Email</th>
                </tr>
                </thead>
               @foreach($remarks as $remark)
                <tr>
                   <td> {{$remark->instruction}}</td>
                   <td> {{$remark->description}}</td>
                   <td> {{$remark->seances->date_seance}}</td>
                   <td> {{$remark->seances()->first()->candidates->name}}</td>
                   <td> {{$remark->seances()->first()->candidates->email}}</td>
                   <td>

Do you have an idea of my problem please? I don't understand ??

Please sign in or create an account to participate in this conversation.