【发布时间】:2014-05-17 22:26:29
【问题描述】:
我想创建一个能够列出用户拥有管理员权限的所有站点的视图。
如何在视图中传递和显示站点名称? 假设我是 id 为 1 的用户,视图将显示我拥有管理员权限的站点名称。
我使用 people_site (admins) 表来记录所有权限。
sites table:
--------------------
id | site_name | address
101 | ABC | 2131
102 | CDE | 23212
103 | EFG | 23231
104 | HIJ | 1234
peoples table:
--------------------
id | first_name | last_name | paswword
1 | Alex | Lee | *******
2 | Bryan | John | *******
people_site (Admin )table:
--------------------
id | people_id | site_id
101 | 1 | 101
102 | 1 | 102
103 | 2 | 103
104 | 1 | 104
105 | 2 | 101
控制器:
public function getManage(){
return View::make('account.manage')
->with('admins', Admin::where('people_id', '=', Auth::user()->id)->orderBy('updated_at', 'desc')->get());
}
查看:
<ul>
@foreach($admins as $admin)
<li><a href="">{{$admin->id}} </a></li>
@endforeach
</ul>
**人物模型:**
public function sites(){
return $this->hasMany('Site');
}
网站模型:
public function peoples(){
return $this->belongsToMany('People');
}
【问题讨论】: