本文整理汇总了PHP中Role::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::findOrFail方法的具体用法?PHP Role::findOrFail怎么用?PHP Role::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::findOrFail方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
* PUT /roles/{id}
*
* @param int $id
* @return Response
*/
public function update($id)
{
$role = \Role::findOrFail($id);
$role->update(\Input::all());
$role->assignPermissions(\Input::get('permissions'));
return \Redirect::route('admin.roles.index');
}
示例2: update
/**
* Update the specified role in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$role = Role::findOrFail($id);
$validator = Validator::make($data = Input::all(), Role::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$role->update($data);
return Redirect::route('roles.index');
}
示例3: update
/**
* Update the specified resource in storage.
* PUT /roles/{id}
*
* @param int $id
* @return Response
*/
public function update($id)
{
$role = Role::findOrFail($id);
if ($role) {
$perms = Input::get('perms');
$permsToAttach = [];
if (Input::has('perms')) {
foreach ($perms as $key => $value) {
$perm = Permission::where('id', '=', $key)->first();
if ($perm) {
array_push($permsToAttach, $perm->id);
}
}
}
$role->perms()->sync($permsToAttach);
if (Input::has('display_name')) {
$role->display_name = Input::get('display_name');
}
$role->save();
return Redirect::to('admin/roles')->with(['roles-notice' => 'Role has been updated']);
}
return Redirect::to('admin/roles')->with(['roles-notice' => 'Error updating role']);
}
示例4: moderator
public static function moderator()
{
return Role::findOrFail(32);
}
示例5: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$role = $this->role->findOrFail($id);
return View::make('roles.show', compact('role'));
}
示例6: destroy
/**
* Remove the specified role from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$role = Role::findOrFail($id);
if (!$role->canDelete()) {
return $this->_access_denied();
}
if (!$role->delete()) {
return $this->_delete_error();
}
if (Request::ajax()) {
return Response::json($this->deleted_message);
}
return Redirect::route('roles.index')->with('notification:success', $this->deleted_message);
}
示例7: edit
public function edit()
{
$role = Role::findOrFail(Input::get('role_id'));
$permissions = $role->perms()->get();
return View::make('roles.edit', compact('role', 'permissions'));
}
示例8: show
/**
* Display the specified role.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$role = Role::findOrFail($id);
$this->layout->title = 'Add Role';
$this->layout->content = View::make('roles.show', compact('role'));
}