本文整理汇总了PHP中app\models\Role::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::save方法的具体用法?PHP Role::save怎么用?PHP Role::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Role
的用法示例。
在下文中一共展示了Role::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
// Don't allow changing the name of the administrator account.
if (!$this->role->isAdministrator()) {
$this->role->name = $this->request->input('name', $this->role->name);
}
$this->role->label = $this->request->input('label', $this->role->label);
return $this->role->save();
}
示例2: save
public function save(Request $request)
{
$as = $request->input('as');
$role = new Role();
$validator = \Validator::make($request->all(), $role->getRules());
$results = new \StdClass();
if ($validator->passes()) {
if ($request->input('id') != 'xxx') {
$role = Role::find($request->input('id'));
$role->name = $request->input('name');
$role->display_name = $request->input('displayname');
$role->description = $request->input('description');
$role->save();
$results->info = 'role create';
} else {
$role = new Role();
$role->name = $request->input('name');
$role->display_name = $request->input('displayname');
$role->description = $request->input('description');
$role->save();
$results->info = 'role edit';
}
$results->status = 1;
$results->result = $role;
} else {
$results->status = 0;
$result = array();
foreach ($validator->errors() as $key => $err) {
array_push($result, $err);
}
$results->result = $result;
}
return response()->json($results);
}
示例3: create
/**
* @param $input
* @throws GeneralException
* @return bool
*/
public function create($input)
{
if (Role::where('role_name', $input['role_name'])->first()) {
throw new GeneralException('That role already exists. Please choose a different name.');
}
if (count($input['assignees_permissions']) == 0) {
throw new GeneralException('You must select at least one permission for this role.');
}
$role = new Role();
$role->role_name = $input['role_name'];
$role->role_slug = $input['role_slug'];
$role->role_description = $input['role_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()
{
$user_1 = new User();
$user_1->name = 'tech';
$user_1->email = 'tech@ordent.co';
$user_1->password = \Hash::make('tech1234');
$user_1->phone = '082214250262';
$user_1->jabatan = 'Technical Administrator';
$user_1->save();
$user_2 = new User();
$user_2->name = 'admin';
$user_2->email = 'admin@ordent.co';
$user_2->password = \Hash::make('admin1234');
$user_2->phone = '082214250262';
$user_2->jabatan = 'Management Administrator';
$user_2->save();
$role_1 = new Role();
$role_1->name = 'tech';
$role_1->display_name = 'tech';
$role_1->description = 'Technical Administration';
$role_1->save();
$role_2 = new Role();
$role_2->name = 'admin';
$role_2->display_name = 'admin';
$role_2->description = 'Management Administration';
$role_2->save();
$user_1->attachRole($role_1);
$user_2->attachRole($role_2);
}
示例5: run
public function run()
{
$adminEmail = Config::get('madison.seeder.admin_email');
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
$independent_sponsor = new Role();
$independent_sponsor->name = 'Independent Sponsor';
$independent_sponsor->save();
$permIds = array();
foreach ($this->adminPermissions as $permClass => $data) {
$perm = new Permission();
foreach ($data as $key => $val) {
$perm->{$key} = $val;
}
$perm->save();
$permIds[] = $perm->id;
}
$admin->perms()->sync($permIds);
$user = User::where('email', '=', $adminEmail)->first();
$user->attachRole($admin);
$createDocPerm = new Permission();
$createDocPerm->name = "independent_sponsor_create_doc";
$createDocPerm->display_name = "Independent Sponsoring";
$createDocPerm->save();
$independent_sponsor->perms()->sync(array($createDocPerm->id));
}
示例6: run
public function run()
{
DB::table('roles')->truncate();
DB::table('role_user')->truncate();
DB::table('permissions')->truncate();
DB::table('permission_role')->truncate();
$admin_role = new Role();
$admin_role->name = 'admin';
$admin_role->display_name = 'Administrator';
$admin_role->description = 'manages everything';
$admin_role->save();
$reviewer_role = new Role();
$reviewer_role->name = 'reviewer';
$reviewer_role->display_name = 'Reviewer';
$reviewer_role->description = 'reviews inserted data';
$reviewer_role->save();
$inserter_role = new Role();
$inserter_role->name = 'inserter';
$inserter_role->display_name = 'Inserter';
$inserter_role->description = 'inserts data about billboards';
$inserter_role->save();
$admin = User::find(1);
$reviewer = User::find(2);
$inserters = User::whereNotIn('id', [$admin->id, $reviewer->id])->get();
$admin->attachRole($admin_role);
$reviewer->attachRole($reviewer_role);
foreach ($inserters as $user) {
$user->attachRole($inserter_role);
}
}
示例7: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$role = new Role();
$role->name = 'Admin';
$role->slug = str_slug('admin');
$role->save();
}
示例8: CreaRoles
public function CreaRoles()
{
$alumno = new Role();
$alumno->name = 'alumno';
$alumno->display_name = 'Usuario Alumno';
// optional
$alumno->description = 'Usuario Alumno puede entrar y reservar';
// optional
$alumno->save();
$coach = new Role();
$coach->name = 'coach';
$coach->display_name = 'Coach';
// optional
$coach->description = 'Coach del Box';
// optional
$coach->save();
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'Usuario Administrator';
// optional
$admin->description = 'Tiene todos los permisos';
// optional
$admin->save();
$recepcion = new Role();
$recepcion->name = 'recepcion';
$recepcion->display_name = 'Usuario Recepción';
// optional
$recepcion->description = 'User is allowed to manage and edit other users';
// optional
$recepcion->save();
}
示例9: setupFoundorAndBaseRolsPermission
public function setupFoundorAndBaseRolsPermission()
{
// Create Roles
$founder = new Role();
$founder->name = 'Founder';
$founder->save();
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
// Create User
$user = new User();
$user->username = 'admin';
$user->display_name = 'Admin';
$user->email = 'admin@local.com';
$user->password = 'admin';
if (!$user->save()) {
Log::info('Unable to create user ' . $user->username, (array) $user->errors());
} else {
Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
}
// Attach Roles to user
$user->roles()->attach($founder->id);
// Create Permissions
$manageContent = new Permission();
$manageContent->name = 'manage_contents';
$manageContent->display_name = 'Manage Content';
$manageContent->save();
$manageUsers = new Permission();
$manageUsers->name = 'manage_users';
$manageUsers->display_name = 'Manage Users';
$manageUsers->save();
// Assign Permission to Role
$founder->perms()->sync([$manageContent->id, $manageUsers->id]);
$admin->perms()->sync([$manageContent->id]);
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$rules = ['name' => 'required|alpha_dash|min:1|max:255', 'display_name' => 'string|max:255', 'description' => 'string', 'permissions' => 'array|integerInArray|existsInArray:permission,id'];
$validator = Validator::make(Input::only(array_keys($rules)), $rules);
if ($validator->fails()) {
throw new ResourceException($validator->errors()->first());
}
$role = new Role();
$fields = ['name'];
foreach ($fields as $key => $field) {
if (Input::has($field)) {
$role->{$field} = Input::get($field);
}
}
//field which can null/empty string
$fields = ['description', 'display_name'];
foreach ($fields as $key => $field) {
if (Input::get($field) === '') {
$role->{$field} = null;
} elseif (Input::has($field)) {
$role->{$field} = Input::get($field);
}
}
$role->save();
$role->perms()->sync(Input::get('permissions', []));
return $this->show($role->id);
}
示例11: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$adminRole = new Role();
$adminRole->name = 'admin';
$adminRole->display_name = 'Admin';
$adminRole->description = 'Admin for backend';
$adminRole->is_admin = 1;
$adminRole->save();
$userRole = new Role();
$userRole->name = 'user';
$userRole->display_name = 'User';
$userRole->description = 'user for backend';
$userRole->is_admin = 0;
$userRole->save();
$admin = User::where('email', 'viethung097@gmail.com')->first();
$assRoleAdmin = new AssignedRole();
$assRoleAdmin->user_id = $admin->id;
$assRoleAdmin->role_id = $adminRole->id;
$assRoleAdmin->save();
$user = User::where('email', 'johnDoe@gmail.com')->first();
$assRoleUser = new AssignedRole();
$assRoleUser->user_id = $user->id;
$assRoleUser->role_id = $userRole->id;
$assRoleAdmin->save();
}
示例12: store
/**
* Store role
*
* @param array $roleData
* @throws NotFoundException, ValidationException
* @return \App\Models\RoleModel
*/
public function store($roleData)
{
try {
if (array_get($roleData, 'id')) {
$role = RoleModel::findOrFail((int) array_get($roleData, 'id'))->fill($roleData);
} else {
$role = new RoleModel();
$role->fill($roleData);
}
} catch (Exception $e) {
throw new NotFoundException(trans('app.notFound'));
}
if (!$role->validate()) {
throw new ValidationException(trans('app.correctErrors'), $role->errors()->toArray());
}
try {
$role->save();
// associate permissions
if (array_get($roleData, 'permission_id')) {
$role->perms()->sync(array_get($roleData, 'permission_id'));
}
} catch (Exception $e) {
throw $e;
}
return $role;
}
示例13: setupRolesPermissions
public function setupRolesPermissions()
{
$master = User::findOrFail(1);
if ($master) {
// Create role
$owner = new Role();
$owner->name = 'master';
$owner->display_name = 'Project Owner';
$owner->description = 'The Master of Universe';
$owner->save();
// Create permissions
$createUser = new Permission();
$createUser->name = 'user-create';
$createUser->display_name = 'Create Users';
$createUser->description = 'Create new users';
$createUser->save();
$editUser = new Permission();
$editUser->name = 'user-edit';
$editUser->display_name = 'Edit Users';
$editUser->description = 'Edit existing users';
$editUser->save();
$deleteUser = new Permission();
$deleteUser->name = 'user-delete';
$deleteUser->display_name = 'Delete Users';
$deleteUser->description = 'Delete existing users';
$deleteUser->save();
// Attach permissions
$owner->attachPermissions([$createUser, $editUser, $deleteUser]);
// Attach roles
$master->attachRole($owner);
// using facade
}
return redirect()->route('access.test');
}
示例14: run
public function run()
{
$roles = ['admin', 'user'];
foreach ($roles as $role) {
$instance = new Role(['role' => $role]);
$instance->save();
}
}
示例15: store
public function store(Request $request)
{
$role = new Role();
$role->name = $request->name;
$role->label = $request->label;
$role->save();
return redirect()->action('Admin\\RolesController@index');
}