本文整理汇总了PHP中app\Permission::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::find方法的具体用法?PHP Permission::find怎么用?PHP Permission::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Permission
的用法示例。
在下文中一共展示了Permission::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: permission_edit
public function permission_edit(Request $request)
{
$this->validate($request, array('permission' => 'required', 'permission_name' => 'required'));
//check repeat before operate the database
$error_msg_route = 'This route has already existed!';
$error_msg_route_name = 'This route name has already existed!';
if (!$request->input('id')) {
if (Permission::where('permission', $request->input('permission'))->first()) {
return redirect()->back()->withErrors($error_msg_route);
}
if (Permission::where('permission_name', $request->input('permission_name'))->first()) {
return redirect()->back()->withErrors($error_msg_route_name);
}
$lastInsert = Permission::create($request->all());
PermissionRole::create(array('permission_id' => $lastInsert->id, 'role_id' => 1));
} else {
$self = Permission::find($request->input('id'));
if ($self->permission != $request->input('permission') && Permission::where('permission', $request->input('permission'))->first()) {
return redirect()->back()->withErrors($error_msg_route);
}
if ($self->permission_name != $request->input('permission_name') && Permission::where('permission_name', $request->input('permission_name'))->first()) {
return redirect()->back()->withErrors($error_msg_route_name);
}
Permission::find($request->input('id'))->update($request->all());
}
return redirect()->back();
}
示例2: addPermissionToGroup
public function addPermissionToGroup(Request $request)
{
$permission = Permission::find($request->permission_id);
$role = Role::find($request->role_id);
$role->attachPermission($permission);
Session::flash('alert-success', 'Permission Granted');
return back();
}
示例3: editPermission
public function editPermission(Request $request)
{
$perm = Permission::find($request->input('id'));
$perm->display_name = $request->input('display_name');
$perm->description = $request->input('description');
$perm->save();
return redirect()->back()->with('alert', ['alert' => 'success', 'body' => 'Berhasil mengubah permission.']);
}
示例4: update
public function update(array $data)
{
$permission = Permission::find($data['id']);
$permission->name = $data['name'];
$permission->display_name = $data['display_name'];
$permission->description = $data['description'];
$permission->save();
return $permission;
}
示例5: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$perm = Permission::find($id);
$perm->name = $request->name;
$perm->display_name = $request->display_name;
$perm->description = $request->description;
$perm->save();
return redirect('permissions');
}
示例6: update
public function update($data)
{
$permission = null;
if (isset($data['id'])) {
$permission = Permission::find($data['id']);
$permission->update($data);
}
return $permission;
}
示例7: findOrThrowException
/**
* @param $id
* @param bool $withRoles
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection|null|static
* @throws GeneralException
*/
public function findOrThrowException($id, $withRoles = false)
{
if (!is_null(Permission::find($id))) {
if ($withRoles) {
return Permission::with('roles')->find($id);
}
return Permission::find($id);
}
throw new GeneralException('That permission does not exist.');
}
示例8: index
public function index()
{
/* // UNIQUE
$owner = new Role();
$owner->name = 'owner';
$owner->display_name = 'Project Owner'; // optional
$owner->description = 'User is the owner of a given project'; // optional
$owner->save();
$admin = new Role();
$admin->name = 'admins';
$admin->display_name = 'User Administrator'; // optional
$admin->description = 'User is allowed to manage and edit other users'; // optional
$admin->save(); */
$owner = Role::find(1);
$admin = Role::find(2);
$user = User::where('name', '=', 'azriz')->first();
// dd($user);
// $user->attachRole($admin);
// dd($user->hasRole('admin')); // true
// UNIQUE
/* $createPost = new Permission();
$createPost->name = 'create-post';
$createPost->display_name = 'Create Posts'; // optional
$createPost->description = 'create new blog posts'; // optional
$createPost->save();
$editUser = new Permission();
$editUser->name = 'edit-user';
$editUser->display_name = 'Edit Users'; // optional
$editUser->description = 'edit existing users'; // optional
$editUser->save();*/
// $admin->attachPermission($createPost);
// equivalent to $admin->perms()->sync(array($createPost->id));
// $owner->attachPermissions(array($createPost, $editUser));
// equivalent to $owner->perms()->sync(array($createPost->id, $editUser->id));
$createPost = Permission::find(1);
$editUser = Permission::find(2);
// dd($user->hasRole('owner')); // false
// dd($user->hasRole('admin')); // true
// dd($user->can('edit-user')); // false
// dd($user->can('create-post')); // true
// dd($user->hasRole(['owner', 'admin'])); // true
// dd($user->can(['edit-user', 'create-post'])); // true
// dd(Entrust::hasRole('admin'));
//Ability
// dd($user->ability('admin,owner', 'create-post,edit-user')); //true, since user is admin and can edit user
//Ability with option
$options = array('validate_all' => true, 'return_type' => 'both');
list($validate, $allValidations) = $user->ability(array('admin', 'owner'), array('create-post', 'edit-user'), $options);
// dd($validate);
// bool(false)
dd($allValidations);
}
示例9: updatePermissions
public function updatePermissions(Request $request, $id)
{
$permission = Permission::find($id);
$this->validate($request, ['display_name' => 'required', 'name' => 'required', 'description' => 'required']);
$input['name'] = $request->get('name');
$input['display_name'] = $request->get('display_name');
$input['description'] = $request->get('description');
$permission->fill($input)->save();
\Session::flash('flash_message', 'Правото беше успешно редактирано!');
return redirect()->route('admin.settings.permissions.index');
}
示例10: updatePermissionData
public static function updatePermissionData(Request $request, $id)
{
$permission = Permission::find($id);
$rules = self::getRules();
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
return Redirect::to('/system/permissions/' . $id . '/edit')->withErrors($validator)->withInput()->send();
} else {
PermissionRepository::savePermission($request, $id);
Session::flash('message', "Permission Details Updated");
return Redirect::to("/system/permissions")->send();
}
}
示例11: handle
/**
* Handle the event.
*
* @param CreateMenuEvent $event
* @return void
*/
public function handle(CreateMenuEvent $event)
{
// return array([
// 'icon' => 'fa-user',
// 'title' => 'Settings'
// ],
// [
// 'icon' => 'fa-trash-o',
// 'title' => 'Settings',
// 'children' => array(
// 'General' => '[url]',
// 'Blog' => '[url]'
// )],
// [
// 'icon' => 'fa-trash-o',
// 'title' => 'Settings',
// 'children' => array(
// 'Haha' => '[url]',
// 'Blog' => '[url]'
// )]
// );
$user = $event->user;
$menu = [];
$user = User::find($user->id);
$main = Menu::where('is_main', '=', 1)->get()->toArray();
foreach ($main as $item) {
$role = [];
$role = Role::find($item['role']);
$child = Menu::where('parent', '=', $item['id'])->get()->toArray();
$me = [];
if ($user->hasRole($role->name)) {
$me['icon'] = $item['icon'];
$me['title'] = $item['name'];
if (isset($child) && !empty($child)) {
foreach ($child as $c) {
$permission = Permission::find($c['permission']);
if ($user->can($permission->name)) {
$me['children'][$c['name']] = $c['route'];
} else {
continue;
}
}
}
} else {
continue;
}
$menu[] = $me;
}
return $menu;
}
示例12: save
/**
* Save permission
*
* @return \Illuminate\Http\JsonResponse
*/
public function save()
{
$input = \Input::except('_token');
$validator = \Validator::make($input, ['label' => 'required|max:255', 'route' => 'required|max:255']);
// When fails
if ($validator->fails()) {
return response()->json(['errors' => $validator->messages()]);
}
// Save changes
$role = empty($input['id']) ? new Permission() : Permission::find($input['id']);
$role->fill($input);
$role->save();
// Response
return response()->json(['success' => 'Settings saved', 'redirect' => url('/admin/permissions/list')]);
}
示例13: create
public function create(Request $request)
{
$user = new \App\User();
$user->username = $request->username;
$user->password = Hash::make($request->password);
$user->email = $request->email;
$user->firstname = $request->firstname;
$user->middlename = $request->middlename;
$user->lastname = $request->lastname;
$user->permission()->associate(\App\Permission::find($request->permission_id));
$user->save();
$photo = new \App\Photo();
$photo->path = 'default_user_thumbnail.png';
$photo->user()->associate($user);
$photo->save();
return $user ? true : false;
}
示例14: addPermission
public function addPermission(Request $request, $id)
{
if ($request->permissionname == "") {
Session::flash('flash_message', 'Please select a role!');
return redirect()->back();
} else {
$permission = Permission::find($request->permissionname);
if (Role::find($id)->roleExist($permission->name)) {
Session::flash('flash_message', 'Role already have this permission!');
return redirect()->back();
}
}
$permission = Permission::find($request->permissionname);
Role::find($id)->givePermissionTo($permission);
Session::flash('flash_message', 'Permission succesfully added!');
return redirect()->back();
}
示例15: update
public function update(Request $request, $id)
{
$permission = Permission::find($id);
if (empty($permission)) {
return $this->failure_noexists();
}
$keys = 'display_name,description';
$data = $this->autoValidate($request, 'permission.store', $keys, $permission);
$permission->update($data);
return $this->success();
}