implementing crm with laravel login page

Implementing CRM System With Laravel Part 4: Preparing login page

As we continue Implementing CRM System with Laravel in this part we will add the system login page to authenticate sales person to access using an email address and password.



Series Topics:


As you may already know in building admin panels the first step is to create the login form before any other step so we will start creating the Auth routes next we will modify the system routes to be prefixed with an /admin prefix so we will add them inside route group then add a new layout for the login.


Generating Auth Scaffolding

Let’s generate the auth scaffolding, this is easy in laravel just run this command in the terminal:

The above command will generate the auth routes and the auth views, now if you checked routes/web.php you will see that laravel append Auth::routes() this method contain the auth routes like /login, /logout, and /register.

Next after we generated the auth routes we need to make some refinements to some files to make authentication work correctly.


Open routes/web.php and modify it like shown here:

In this code i enclosed the admin routes using a route group of /admin and applied the auth middleware to those routes so only the logged in users can view those pages.

Also i modified the default route “/” to redirect to the /admin route.


Add a new layout file resources/views/layout/auth.blade.php with the below code

Modify resources/views/auth/login.blade.php like this:

As you see this login form comes already with the AdminLTE theme, i replaced the default laravel login form with this form.


Modify app/Http/Controllers/Auth/LoginController.php:

As shown above i have modified the LoginController where i override the login method to enable active users only to login “is_active“.




I updated the above files to display the correct username based on the currently logged in user also i displayed a placeholder image if the user has no image, you can download the placeholder image from here and place it inside public/theme/dist/img folder. Finally i added the logout link and logout form in.


Don’t forget to create an uploads/ directory inside of public/ directory with a writable permissions similar to this structure:

crm uploads directory


Now try to navigate to http://localhost/crm/public it will show you the login page, now login using email: and password: admin.

Administrator Middleware

We will add a new middleware to allow or disallow certain users from accessing certain areas bases on if the user is super admin “is_admin=1” or it has a permission to access that area.


As shown i checked for the current user is_admin property, if it equal to 1 then it’s allowed, otherwise we check if the user has a permission for the current route action, as you see i send a parameter to the function called permission, this parameter will be passed inside each controller you want to authorize access to it.


I have added the middleware to the laravel kernel $routeMiddleware property with alias “admin“.





Continue to Part 5: Beginning the Users Module


Share this: