本文整理汇总了PHP中app\Permission::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::with方法的具体用法?PHP Permission::with怎么用?PHP Permission::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Permission
的用法示例。
在下文中一共展示了Permission::with方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllPermissions
/**
* @param string $order_by
* @param string $sort
* @param bool $withRoles
* @return mixed
*/
public function getAllPermissions($order_by = 'id', $sort = 'asc', $withRoles = true)
{
if ($withRoles) {
return Permission::with('roles')->orderBy($order_by, $sort)->get();
}
return Permission::orderBy($order_by, $sort)->get();
}
示例2: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$this->authorize('permissions-edit');
$permission = Permission::with('roles')->findOrFail($id);
$roles = Role::orderBy('display_name')->get();
return view('permissions.edit', compact('permission', 'roles'));
}
示例3: getPermissions
/**
* Fetch the collection of site permissions.
*
* @return \Illuminate\Database\Eloquent\Collection
* @todo find better solution to prevent missing table error whe permissions table not yet migrated.
*/
protected function getPermissions()
{
try {
return Permission::with('roles')->get();
} catch (\Exception $e) {
return [];
}
}
示例4: getPermissions
/**
* Fetch the collection of site permissions.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function getPermissions()
{
try {
return Permission::with('roles')->get();
} catch (\Exception $e) {
\Log::alert('No se pudo registrar los permisos');
return [];
}
}
示例5: boot
/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function boot(GateContract $gate)
{
parent::registerPolicies($gate);
$permissions = \App\Permission::with('roles')->get();
foreach ($permissions as $permission) {
$gate->define($permission->name, function ($user) use($permission) {
return $user->hasPermission($permission);
});
}
}
示例6: boot
/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
$permissions = Permission::with('roles')->get();
foreach ($permissions as $permission) {
$gate->define($permission->slug, function ($user) use($permission) {
return $permission->roles->contains($user->role);
});
}
// $gate->define('show-product', function($user, $product){
// return $user->id == $product->supplier_id;
// });
}
示例7: boot
/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function boot(GateContract $gate)
{
parent::registerPolicies($gate);
$gate->before(function ($user, $ability) {
if ($user->isAdmin()) {
return true;
}
});
if (\Schema::hasTable('permissions')) {
$permissions = \App\Permission::with('roles')->get();
foreach ($permissions as $permission) {
$gate->define($permission->slug, function ($user) use($permission) {
return $user->hasPermission($permission);
});
}
}
}
示例8: getPermissions
protected function getPermissions()
{
return Permission::with('roles')->get();
}
示例9: getPermissions
public function getPermissions()
{
return Permission::with('roles')->get();
}
示例10: index
public function index()
{
$permissions = Permission::with('roles')->paginate(20);
return view('admin.permission.index', ['permissions' => $permissions]);
}
示例11: function
// Route::post('/api/users/assign/role', 'UserPivotApiController@assignRole');
Route::group(['prefix' => 'api'], function () {
Route::get('user-data/{id}', 'IndexController@user');
Route::get('user-id', 'UserPivotApiController@userId');
Route::get('users/pivots', 'UserPivotApiController@index');
Route::post('users/assign/role', 'UserPivotApiController@assignRole');
});
Route::group(['middleware' => ['web']], function () {
//
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController@index');
});
Route::group(['middleware' => 'auth'], function () {
Route::resource('posts', 'PostsController');
});
Route::get('users', function () {
return \App\User::all();
});
Route::get('users/{id}', function ($id) {
return \App\User::with('roles')->find(1);
});
Route::get('roles', function () {
return \App\Permission::with('roles')->get();
});
Route::group(['prefix' => 'acl'], function () {
Route::get('', 'UserPivotController@index');
Route::get('users', 'UserPivotController@allUser');
Route::get('users/{id}', ['as' => 'user.show', 'uses' => 'UserPivotController@show']);
});
示例12: getSystemUsers
public function getSystemUsers()
{
return \App\Permission::with('users')->get()->get(1)->users;
}