本文整理汇总了PHP中app\models\Role::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::where方法的具体用法?PHP Role::where怎么用?PHP Role::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Role
的用法示例。
在下文中一共展示了Role::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update roles.
*
* @param array $inputs
* @return void
*/
public function update($inputs)
{
foreach ($inputs as $key => $value) {
$role = $this->role->where('slug', $key)->firstOrFail();
$role->title = $value;
$role->save();
}
}
示例2: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$role = Role::where('name', 'admin')->first();
$customer = Customer::create(['name' => 'test']);
$customer->user()->save(new User(['email' => 't@t.test', 'password' => bcrypt('testing')]));
$customer->user->assignRole($role);
}
示例3: create
/**
* @param $input
* @throws GeneralException
* @return bool
*/
public function create(array $input)
{
if (Role::where('name', '=', $input['name'])->first()) {
throw new GeneralException('That role already exists. Please choose a different name.');
}
if (isset($input['assignees_permissions']) && count($input['assignees_permissions']) == 0) {
throw new GeneralException('You must select at least one permission for this role.');
}
$role = new Role();
$role->name = $input['name'];
$role->display_name = $input['display_name'];
$role->description = $input['description'];
if ($role->save()) {
$current = $input['assignees_permissions'];
$permissions = [];
if (count($current)) {
foreach ($current as $perm) {
if (is_numeric($perm)) {
array_push($permissions, $perm);
}
}
}
$role->attachPermissions($permissions);
return true;
}
throw new GeneralException('There was a problem creating this role. Please try again.');
}
示例4: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
// $u1 = \App\User::create(
// ['name'=>'super_admin', 'email'=>'super_admin@oa.com', 'password'=>Hash::make('123456')]
// );
$user = \App\User::where('email', '=', 'super_admin@oa.com')->first();
echo $user . "\n";
// $role = new \App\Models\Role();
// $role->name = 'SuperUser';
// $role->display_name = '超级管理员'; // optional
// $role->description = '网站超管'; // optional
// $role->save();
$role = \App\Models\Role::where('name', '=', 'SuperUser')->first();
echo $role . "\n";
//
// $user->attachRole($role);
//
$permission = new \App\Models\Permission();
$permission->name = 'create-post';
$permission->display_name = 'Create Posts';
// optional
$permission->description = 'create new blog posts';
// optional
$permission->save();
$role->attachPermission($permission);
}
示例5: postLogin
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function postLogin(Request $request)
{
// Auth::logout();
if (Auth::check()) {
return redirect('/posts');
}
// return view('login.login');
$username = $request->username;
$password = $request->password;
$field = filter_var($username, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
$pass = 'Password';
if (Auth::attempt([$field => $username, 'password' => $password])) {
$user = Auth::user();
$role = Role::where('userId', $user->objectId)->first();
if ($role && $role->name == 'Admin') {
return redirect('/posts');
} else {
Auth::logout();
Session::flash('error', 'You are not admin right.');
return redirect('/administration')->with(['error' => 'You are not admin right.']);
}
} else {
Session::flash('error', 'Username or Password is wrong.');
return redirect('/administration')->with(['error' => 'Username or Password is wrong.']);
}
}
示例6: store
/**
* Store a newly created ShareUser in storage.
* POST /shareUsers
*
* @param Request $request
*
* @return Response
*/
public function store(Request $request)
{
if (sizeof(ShareUser::$rules) > 0) {
$validator = $this->validateRequestOrFail($request, ShareUser::$rules);
if ($validator) {
return $validator;
}
}
$input = $request->all();
$user = User::where('id', $input['user_id'])->first();
if ($user) {
$shared_with_other_account = User::where('phoneNo', $user->phoneNo)->lists('id');
if (count($shared_with_other_account) > 0) {
$alreadyShared = ShareUser::where('share_objectId', $input['share_objectId'])->wherein('user_id', $shared_with_other_account)->get();
if (count($alreadyShared) > 0) {
return response()->json("The share object id has already been taken.", 403);
}
}
$shareUsers = $this->shareUserRepository->create($input);
$shared_user = User::where('objectId', $shareUsers->share_objectId)->first();
if ($shared_user) {
$shared_user->points += 10;
$shared_user->update();
$user->shared = true;
$user->update();
$role = Role::where('userId', $user->objectId)->first();
if ($role) {
$user['role'] = $role->name;
} else {
$user['role'] = 'User';
}
}
return $this->sendResponse($user->toArray(), "ShareUser saved successfully");
}
}
示例7: __construct
public function __construct()
{
$role = Role::where('name', 'user')->first();
$this->middleware('auth');
$this->middleware('session');
$this->authorize('auth', $role);
}
示例8: save
/**
* Save the User.
*
* @param App\Models\User $user
* @param Array $inputs
* @return void
*/
private function save($user, $inputs)
{
if (isset($inputs['seen'])) {
$user->seen = $inputs['seen'] == 'true';
} else {
$user->username = $inputs['username'];
$user->email = $inputs['email'];
if (isset($inputs['role'])) {
$user->role_id = $inputs['role'];
} else {
$role_user = $this->role->where('slug', 'user')->first();
$user->role_id = $role_user->id;
}
}
$user->save();
}
示例9: __construct
public function __construct()
{
$role = Role::where('name', 'admin')->first();
//Mejor guardar el role en la session
$this->middleware('auth');
$this->authorize('auth', $role);
$this->middleware('session');
}
示例10: checkRole
public function checkRole($id)
{
$role = Role::where('userId', $id)->first();
if ($role) {
return response()->json($role->name);
}
return response()->json('User');
}
示例11: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$user = new \App\Models\User();
$user->email = "admin@success.local";
$user->password = \Hash::make("admin");
$user->save();
$role = \App\Models\Role::where("key", "=", "admin")->first();
$user->roles()->attach($role->id);
}
示例12: destroyRole
/**
* Locate role, detach from perms and users then delete.
*
* @param $name
*/
protected static function destroyRole($name)
{
$roleActiveDirectoryInspector = Role::where('name', $name)->first();
if ($roleActiveDirectoryInspector) {
$roleActiveDirectoryInspector->perms()->detach();
$roleActiveDirectoryInspector->users()->detach();
Role::destroy($roleActiveDirectoryInspector->id);
}
}
示例13: authorize
public static function authorize()
{
$val = 0;
$role = \App\Models\Role::where('id', Auth::user()->role_id)->first();
if ($role) {
$val = $role->authorize;
}
return $val;
}
示例14: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$roles = ['Normal User', 'Pro User', 'Admin', 'Free'];
foreach ($roles as $r) {
$role = Role::where('name', '=', $r)->first();
if (!$role) {
Role::create(['name' => $r]);
}
}
}
示例15: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
if (Role::get()->count() == 0) {
Role::create(['name' => 'admin', 'display_name' => 'Admin', 'description' => 'User can adminstrate the site']);
Role::create(['name' => 'user', 'display_name' => 'User', 'description' => 'User can navigate the site']);
}
if (User::get()->count() == 0) {
User::create(['name' => env('ROOT_USER_NAME', 'Test User'), 'email' => env('ROOT_USER_EMAIL', 'testuser@test.com'), 'password' => Hash::make(env('ROOT_USER_PASSWORD', 'password'))])->attachRole(Role::where('name', '=', 'admin')->first());
}
}