本文整理汇总了PHP中Role::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::where方法的具体用法?PHP Role::where怎么用?PHP Role::where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
// create default user asset
$asset = Asset::where('filename', '=', 'default.png')->first();
if ($asset == NULL) {
$asset = new Asset();
$asset->filename = 'default.png';
$asset->path = 'assets/content/users';
$asset->save();
}
$admin = Role::where('name', '=', 'Admin')->first();
// create default roles
if ($admin == NULL) {
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
}
$adminUser = User::where('username', '=', 'admin')->first();
if ($adminUser != NULL) {
echo "Admin User Already Exsit";
} else {
$adminUser = new User();
$adminUser->username = 'admin';
$adminUser->email = 'admin@admin.com';
$adminUser->password = 'admin';
$adminUser->password_confirmation = 'admin';
$adminUser->confirmation_code = md5(uniqid(mt_rand(), true));
if ($adminUser->save()) {
$adminUser->attachRole($admin);
echo "Admin User Created";
}
}
}
示例2: run
public function run()
{
$faker = Faker\Factory::create('es_AR');
DB::table('users')->delete();
//Creamos usuario generico inicial
$id = DB::table('users')->insertGetId(array('username' => 'admin', 'password' => App::make('hash')->make('admin'), 'email' => 'admin@test.com', 'nombre' => 'ADMINISTRADOR', 'apepat' => 'TEST', 'apemat' => '', 'confirmed' => true, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
$rol_id = Role::where(['name' => 'Administrador'])->first()->id;
DB::table('assigned_roles')->insert(array('user_id' => $id, 'role_id' => $rol_id));
foreach (range(1, 1500) as $idx) {
if ($idx % 10 == 0) {
echo ".";
}
if ($idx % 50 == 0) {
echo " ";
}
if ($idx % 100 == 0) {
echo "\n";
}
if ($idx % 500 == 0) {
echo "\n";
}
try {
DB::table('users')->insert(array('username' => str_ireplace(['á', 'é', 'í', 'ó', 'ú'], ['a', 'e', 'i', 'o', 'u'], mb_strtolower(str_replace(" ", "", $faker->userName))), 'password' => App::make('hash')->make($faker->word), 'email' => str_ireplace(['á', 'é', 'í', 'ó', 'ú'], ['a', 'e', 'i', 'o', 'u'], $faker->safeEmail), 'nombre' => mb_strtoupper($faker->firstName), 'apepat' => mb_strtoupper($faker->lastName), 'apemat' => mb_strtoupper($faker->lastName), 'confirmed' => true, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
} catch (Exception $e) {
//error_log($e->getMessage());
}
}
}
示例3: store
/**
* Stores new account
*
* @return Illuminate\Http\Response
*/
public function store()
{
$repo = App::make('UserRepository');
$user = $repo->signup(Input::all());
if ($user->id) {
try {
if (Config::get('confide::signup_email')) {
Mail::queueOn(Config::get('confide::email_queue'), Config::get('confide::email_account_confirmation'), compact('user'), function ($message) use($user) {
$message->to($user->email, $user->username)->subject(Lang::get('confide::confide.email.account_confirmation.subject'));
});
}
$role = Role::where('name', '=', 'admin')->first();
$user->roles()->attach($role->id);
$notice_msg = 'Su cuenta ha sido creada satisfactoriamente. Revisa tu correo';
return Redirect::action('UsersController@login')->with('notice', $notice_msg);
} catch (Exception $exc) {
$userReg = User::findOrFail($user->id);
$userReg->delete(['id']);
return Redirect::back()->with('error', 'Falló envío de correo, intente registrarse nuevamente');
}
} else {
$error = $user->errors()->all(':message');
return Redirect::back()->withInput(Input::except('password'))->with('error', $error);
}
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// $inputs = Input::only(static::$createColumns);
// $rules = static::$createValidation;
$validator = Validator::make(Input::all(), User::$rules);
if ($validator->fails()) {
$messages = $validator->errors();
return Redirect::action('UsersController@create')->withInput(Input::except('password', 'password_confirmation'))->withErrors($messages);
// ->with('error', $error);
} else {
$repo = App::make('UserRepository');
$user = $repo->signup(Input::all());
if ($user->id) {
if (Config::get('confide::signup_email')) {
Mail::queueOn(Config::get('confide::email_queue'), Config::get('confide::email_account_confirmation'), compact('user'), function ($message) use($user) {
$message->to($user->email, $user->username)->subject(Lang::get('confide::confide.email.account_confirmation.subject'));
});
}
$userRole = Role::where('name', 'volunteer')->first();
$user->attachRole($userRole->id);
// $user->confirmed = true;
// $user->save();
// $result = Auth::attempt(['email' => $user->email, 'password' => Input::get('password')]);
return Redirect::action('UsersController@create2')->with('notice', Lang::get('confide::confide.alerts.account_created'));
} else {
$error = $user->errors()->all(':message');
// dd($error);
}
//
}
//closes else for validator-if
}
示例5: run
public function run()
{
DB::table('users')->delete();
$user = User::create(array('id' => 1, 'username' => 'admin', 'first_name' => 'Yamid', 'last_name' => 'Viloria Ortega', 'email' => 'admin@admin.com', 'password' => Hash::make('1234'), 'created_at' => new DateTime(), 'updated_at' => new DateTime()));
$role = Role::where('name', '=', 'admin')->get()->first();
$user->attachRole($role);
}
示例6: run
public function run()
{
DB::table('permissions')->delete();
$roles = array();
$roles[0] = Role::where('name', '=', 'admin')->first()->id;
$roles[1] = Role::where('name', '=', 'moderator')->first()->id;
$resources = Resource::all();
$actions = array();
$actions[0] = Action::where('name', '=', 'manage')->first()->id;
/*
$actions[0] = Action::where('name','=','create')->first()->id;
$actions[1] = Action::where('name','=','read')->first()->id;
$actions[2] = Action::where('name','=','update')->first()->id;
$actions[3] = Action::where('name','=','delete')->first()->id
*/
$data = array();
foreach ($roles as $role) {
foreach ($resources as $resource) {
foreach ($actions as $action) {
$data[] = array('role_id' => $role, 'type' => $role == $roles[0] || $resource->name != 'role' && $resource->name != 'auth' ? 'allow' : 'deny', 'action_id' => $action, 'resource_id' => $resource->id);
}
}
}
DB::table('permissions')->insert($data);
}
示例7: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
if ($this->argument('name')) {
$name = trim($this->argument('name'));
$role = Role::where('name', '=', $name)->first();
if ($role) {
$this->info("Role '{$name}' already exists.");
exit;
}
$role = new Role();
$role->name = $name;
$role->save();
$this->info('Role saved successfully.');
} else {
$roles = Role::all();
$this->info('Existing Roles:');
foreach ($roles as $role) {
$this->info($role->name);
}
$continue = $this->ask("Would you still like to add a new role? (yes/no)");
if ('yes' === trim(strtolower($continue))) {
$name = $this->ask("What's the new role's name?");
$role = new Role();
$role->name = trim($name);
$role->save();
$this->info('Role saved successfully.');
}
}
}
示例8: run
public function run()
{
$admin = Role::where('name', '=', 'administrator')->first();
$perms = Permission::all();
$admin->perms()->sync(array_pluck($perms, 'id'));
$man = Role::where('name', '=', 'users manager')->first();
$perms = Permission::where('name', '=', 'manage_users')->orWhere('name', '=', 'delete_users')->get();
$man->perms()->sync(array_pluck($perms, 'id'));
$man = Role::where('name', '=', 'premium author')->first();
$perms = Permission::where('name', '=', 'manage_premium_casts')->orWhere('name', '=', 'manage_free_casts')->orWhere('name', '=', 'manage_series')->get();
$man->perms()->sync(array_pluck($perms, 'id'));
$man = Role::where('name', '=', 'author')->first();
$perms = Permission::where('name', '=', 'manage_free_casts')->orWhere('name', '=', 'manage_series')->get();
$man->perms()->sync(array_pluck($perms, 'id'));
$man = Role::where('name', '=', 'eraser')->first();
$perms = Permission::where('name', '=', 'delete_series')->orWhere('name', '=', 'delete_casts')->get();
$man->perms()->sync(array_pluck($perms, 'id'));
$man = Role::where('name', '=', 'premium user')->first();
$perms = Permission::where('name', '=', 'view_premium_casts')->orWhere('name', '=', 'view_free_casts')->get();
$man->perms()->sync(array_pluck($perms, 'id'));
$man = Role::where('name', '=', 'user')->first();
$perms = Permission::where('name', '=', 'view_free_casts')->get();
$man->perms()->sync(array_pluck($perms, 'id'));
$man = Role::where('name', '=', 'guest')->first();
$perms = Permission::where('name', '=', 'view_free_casts')->get();
$man->perms()->sync(array_pluck($perms, 'id'));
}
示例9: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
//1. Create Independent Sponsor role
$sponsorRole = Role::where('name', '=', 'Independent Sponsor')->first();
if (!$sponsorRole) {
$sponsorRole = new Role();
$sponsorRole->name = "Independent Sponsor";
$sponsorRole->save();
$this->info("Independent Sponsor role created.");
} else {
$this->info("Independent Sponsor role exists.");
}
//2. Add Independent Sponsor role to all Admins
$adminRole = Role::where('name', 'Admin')->first();
$admins = $adminRole->users()->get();
foreach ($admins as $admin) {
$this->info('--------------------------------------------------');
if ($admin->hasRole($sponsorRole->name)) {
$this->info($admin->email . " already set as Independent Sponsor");
} else {
$admin->attachRole($sponsorRole);
$this->info($admin->email . " set as " . $sponsorRole->name);
}
//3. Remove Admin role from non-admin users
$stayAdmin = strtolower(trim($this->ask("Keep " . $admin->email . " as an Admin? (yes/no)")));
if ($stayAdmin != 'yes') {
$admin->detachRole($adminRole);
$this->info("Removed Admin role from " . $admin->email);
} else {
$this->info($admin->email . " still set as an Admin.");
}
}
}
示例10: creating
public function creating($user)
{
// generate activation key for the user being created
$user->activation_key = md5(uniqid(rand(), true));
// @TODO: use a Role repository
$role = \Role::where('name', 'member')->first();
$user->role()->associate($role);
}
示例11: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$roles = $this->role->all();
if (Request::ajax()) {
$roles = Role::where('role', 'like', '%' . Input::get('term', '') . '%')->get(array('id', 'role'));
return $roles;
}
return View::make('roles.index', compact('roles'));
}
示例12: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$roles = $this->role->paginate(Settings::getValue('TABLE_ELEMENTS'));
if (Request::ajax()) {
$roles = Role::where('role', 'like', '%' . Input::get('term', '') . '%')->get(array('id', 'role'));
return $roles;
}
return View::make('backend.roles.index', compact('roles'));
}
示例13: updateUser
public function updateUser($id)
{
$user = User::find($id);
$data = Input::all();
$user->detachRoles($user->roles);
$user->update($data);
$user->attachRole(Role::where('name', $data['role'])->first());
return Redirect::back()->with('message', 'berhasil update user');
}
示例14: isAdmin
public static function isAdmin()
{
$role = Role::where('user_id', static::user()->id)->first();
if ($role->permission == 1) {
return true;
} else {
return false;
}
}
示例15: getRoleId
public static function getRoleId($rolename)
{
$role = Role::where('rolename', $rolename)->first();
if ($role) {
return $role->_id;
} else {
return false;
}
}