Laravel Mini CRM for Beginners in 1 Hour: Step-by-Step

4 min read 2 hours ago
Published on Oct 12, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, you'll learn how to build a simple Customer Relationship Management (CRM) application using Laravel within an hour. This step-by-step guide is designed for beginners and covers the essential features including user management, roles, and CRUD operations for clients, projects, and tasks. By the end of this tutorial, you’ll have a functional mini CRM that you can expand upon.

Step 1: Install Laravel and Breeze

To start, ensure you have Composer installed on your machine. Follow these steps to set up Laravel and Breeze.

  1. Create a new Laravel project:

    composer create-project --prefer-dist laravel/laravel mini-crm
    
  2. Navigate to the project directory:

    cd mini-crm
    
  3. Install Laravel Breeze for authentication:

    composer require laravel/breeze --dev
    
  4. Run Breeze installation:

    php artisan breeze:install
    
  5. Migrate the database:

    php artisan migrate
    
  6. Install frontend dependencies and compile assets:

    npm install && npm run dev
    
  7. Start the Laravel development server:

    php artisan serve
    

Step 2: User CRUD Operations

Next, implement CRUD operations for user management.

  1. Create a UserController:

    php artisan make:controller UserController
    
  2. Define routes in web.php:

    Route::resource('users', UserController::class);
    
  3. Implement CRUD methods in UserController:

    • Index: List all users.
    • Create: Show form for creating a new user.
    • Store: Save the new user.
    • Edit: Show form for editing an existing user.
    • Update: Save the updated user.
    • Destroy: Delete a user.
  4. Create views for each of the CRUD operations in resources/views/users.

Step 3: Adding Admin Role

To enhance user management, add an admin role.

  1. Add role column to the users table:

    php artisan make:migration add_role_to_users_table --table=users
    
  2. Update the migration file to include the role column:

    $table->string('role')->default('user');
    
  3. Run the migration:

    php artisan migrate
    
  4. Update the User registration and editing forms to include a role selection.

Step 4: Clients CRUD Operations

Now, let's create a CRUD interface for managing clients.

  1. Create a Client model and migration:

    php artisan make:model Client -m
    
  2. Define the client fields in the migration file and run:

    php artisan migrate
    
  3. Create ClientController for CRUD operations:

    php artisan make:controller ClientController
    
  4. Define routes for clients similar to users.

  5. Implement CRUD methods in ClientController and create corresponding views.

Step 5: Projects CRUD Operations

Next, implement CRUD operations for projects.

  1. Create a Project model and migration:

    php artisan make:model Project -m
    
  2. Define project fields in the migration file and run:

    php artisan migrate
    
  3. Create ProjectController and set up routes.

  4. Implement CRUD methods in ProjectController and create views.

Step 6: Tasks CRUD Operations

Finally, add CRUD functionalities for tasks.

  1. Create a Task model and migration:

    php artisan make:model Task -m
    
  2. Define task fields in the migration file and run:

    php artisan migrate
    
  3. Create TaskController and define routes.

  4. Implement CRUD methods in TaskController and create views.

Step 7: Permissions for Delete

To manage permissions effectively, especially for delete actions:

  1. Use Laravel policies to handle user permissions.

  2. Create a policy for users:

    php artisan make:policy UserPolicy
    
  3. Define permissions within the policy methods.

  4. Register the policy in AuthServiceProvider.

  5. Use the policy in your controllers to restrict delete actions based on user roles.

Conclusion

You have now built a mini CRM application using Laravel. You have implemented user authentication, CRUD operations for users, clients, projects, and tasks, and added role management and permissions.

Next Steps

  • Explore Laravel's advanced features like middleware and event broadcasting.
  • Customize the UI using frontend frameworks or libraries.
  • Consider deploying your application to a hosting platform.