User Management

The Admin user has access to a users management table page.


The user management can be accessed by clicking User Management from the Laravel Examples section of the sidebar or adding /user-management in the url. This page is available for users with the Admin role and the user is able to add, edit and delete other users. For adding a new user you can press the Add User button or add in the url /new. If you would like to edit or delete an user you can click on the icon from the Action column. It is also possible to sort the fields and change pagination.

On the page for adding a new user you will find a form which allows you to fill the information. All pages are generated using blade templates.

In /resources/views/larave/users/create.blade.php

                              
    <div class="col-6">
        <label class="form-label">First Name</label>
        <div class="input-group">
            <input id="firstname" name="firstname" class="form-control" type="text" placeholder="Firstname">
        </div>
        @error('firstname')
            <p class='text-danger text-xs'> {{ $message }} </p>
        @enderror
    </div>
                              
                            

The App\Http\Controllers\UserController.php takes care of data validation and creating the new user:

                          
    $user = User::create([
        'firstname' => $request->get('firstname'),
        'lastname' => $request->get('lastname'),
        'password' => $request->get('password'),
        'role_id' => $request->get('role'),
        'email' => $request->get('email'),
        'gender' => $request->get('gender'),
        'location' => $request->get('location'),
        'phone' => $request->get('phone'),
        'language' => $request->get('language'),
        'birthday' => $birthday,
        'skills' => $request->get('skills')
    ]);

    if($request->file('avatar')) {
        $user->update([
            'avatar' => $request->file('avatar')->store('/', 'avatars')
        ]);
    }
                          
                        

Once the user pressed Save at the end of the form the new user is added to the table.

For authorizing this actions have been used policies such as App\Policies\UserPolicy:

                          
    /**
    * Determine whether the authenticate user can manage other users.
    *
    * @param  \App\User  $user
    * @return boolean
    */
    public function manageUsers(User $user)
    {
        return $user->isAdmin();
    }