php - Why show Undefined variable error in Laravel 5.2? -


first take working file.

actioncontroller.php:

namespace app\http\controllers;  use illuminate\http\request; use app\action; use app\role; use app\http\requests;  class actioncontroller extends controller {     /**      * display listing of resource.      *      * @return \illuminate\http\response      */     public function index()     {         //          $actions = action::where('id','>=',1)->paginate(10);          $roles = role::all();         $data = ['roles' => $roles];         return view('actions.index',['actions'=>$actions]);     } 

index.blade.php:

<table id="example2" class="table table-bordered table-hover" width="100%">      <thead>         <tr>             <th>uri</th>             <th>action</th>             @foreach($roles $role)                <th>{{$role->role}}</th>             @endforeach         </tr>     </thead>         <tbody>     @foreach($actions $action)          <tr>             <td>{{$action->uri}}</td>             <td>{{$action->action}}</td>             <td>{{$action->role}}</td>         </tr>      @endforeach     </tbody> </table> 

when trying show actions in foreach working fine when want show roles in foreach loop showing undefined variable: roles error. how can show roles in actions index?

because not passing $roles variable within view should passed as

return view('actions.index',['actions'=>$actions])->withroles($roles); 

or can pass of actions

return view('actions.index',['actions'=>$actions,'roles' => $roles]); 

or

$data = ['actions'=>$actions,'roles' => $roles]; return view('actions.index',$data); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -