【发布时间】:2017-10-24 16:03:28
【问题描述】:
先看看我的工作文件。
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 a listing of the 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 as $role)
<th>{{$role->role}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($actions as $action)
<tr>
<td>{{$action->uri}}</td>
<td>{{$action->action}}</td>
<td>{{$action->role}}</td>
</tr>
@endforeach
</tbody>
</table>
当我试图在foreach 中显示actions 时,它工作正常,但是当我想在foreach 循环中显示roles 时,它显示Undefined variable: roles 错误。如何在操作索引中显示角色?
【问题讨论】:
标签: php mysql laravel laravel-5.2