/** * List out all the permissions of all users. * * @todo Refactor out mapping to a trait. * * @return \Illuminate\Contracts\View\View */ public function index() { $permissions = collect(['*', 'admin.*', 'api.*']); $users = $this->user->all()->map(function ($user) use($permissions) { $user->permissions = collect([]); $permissions->map(function ($permission) use($user) { $user->permissions->push($this->buildPermissibleLookup($user, $permission)); }); return $user; }); return view('gate-admin::permissions.index', compact('users')); }
/** * Set up the tests * * @return void */ public function setUp() { parent::setUp(); Role::observe(new AddSlugAttribute()); User::observe(new UserObserver()); Permission::observe(new PermissionObserver()); }
/** * Register any other events for your application. * * @return void */ public function boot() { $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); Role::observe(new AddSlugAttribute()); User::observe(new UserObserver()); Permission::observe(new PermissionObserver()); }
/** @test **/ function it_updates_the_image_path() { $user = User::create(['email' => '*****@*****.**', 'password' => 'password']); $this->assertNull($user->profile->image); $user->updateImage($expected = '/path/to/image.jpg'); $this->assertEquals($expected, $user->profile->image); }
/** * Validate the user credentails and return really decent flash messaging. * * @param array $credentials * @param string $role * @return bool|\Alchemy\Gate\User */ private function validateUser(array $credentials, string $role = null) { $user = User::where('email', $credentials['email'])->first(); if (!$user) { flash()->error('Uh-oh', 'The email provided does not exist in the system.'); return false; } if (!app(Guard::class)->validate($credentials)) { flash()->error('Uh-oh', 'The password does not match the given email address.'); return false; } if (!$user->is_active) { flash()->error('Uh-oh', 'Your account has not been activated.'); return false; } if (!$user->hasRoles($role)) { flash()->error('Uh-oh', 'You are not authorized to access this page.'); return false; } return $user; }
public function created(User $user) { // Create a new profile and associate it. $user->profile()->save(new Profile()); event(new UserRegistered($user)); }
/** * Execute the job. * * @param User $user * @return void */ public function handle(User $user) { $user->destroy($user->expired()->lists('id')->all()); }
/** * Delete the given user and redirect to the index page. * * @param User $user * @return \Illuminate\Http\RedirectResponse */ public function destroy(User $user) { User::destroy($user->id); flash()->success('Deleted!', "The user has been deleted."); return redirect()->route('admin.users.index'); }
/** * Run the seeder. * * @return void */ public function run() { User::create(['email' => '*****@*****.**'])->addRoles('administrator')->activate()->updateProfile(['name' => 'Jaggy Gauran'])->changePassword('hangin'); User::create(['email' => '*****@*****.**'])->addRoles('standard')->activate()->updateProfile(['name' => 'Jaggy Gauran'])->changePassword('hangin'); }