Laravel Voyager is a powerful admin panel package for Laravel that allows you to create and manage admin interfaces easily. It provides features such as CRUD (Create, Read, Update, Delete) management, a media manager, and more.
Step 1: Install Laravel
First, create a new Laravel project if you don’t have one:
1 2 |
composer create-project --prefer-dist laravel/laravel laravel-voyager cd laravel-voyager |
Step 2: Set Up the Database
Configure your database settings in the .env
file:
1 2 3 4 5 6 |
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_username DB_PASSWORD=your_password |
Step 3: Install Voyager
Install Voyager via Composer:
1 |
composer require tcg/voyager |
Step 4: Publish Voyager Assets
Publish Voyager’s configuration and assets:
1 |
php artisan voyager:install |
If you want to seed the database with dummy data (including user accounts), you can use:
1 |
php artisan voyager:install --with-dummy |
Step 5: Configure Authentication
Voyager comes with its own user management. You can create an admin user using the following command:
1 |
php artisan voyager:admin your@email.com --create |
You’ll be prompted to enter a password for the admin user.
Step 6: Access Voyager Admin Panel
Start your Laravel server:
1 |
php artisan serve |
Visit http://localhost:8000/admin
in your browser. Use the admin credentials you created to log in.
Step 7: Create and Manage BREAD
BREAD stands for Browse, Read, Edit, Add, and Delete. Voyager allows you to create BREAD for your database tables easily.
- Create a New Table: You can create a new migration for a table using:
bash
1php artisan make:migration create_posts_table --create=postsDefine your table structure in the migration file and run:
bash
1php artisan migrate - Add BREAD: In the Voyager admin panel, navigate to Tools > Database. Select your newly created table and click BREAD.
- Configure BREAD: You can set up the fields, validation rules, and visibility options for your BREAD. This setup allows you to customize how the CRUD interface will look and function.
Step 8: Customize Voyager
Voyager provides various ways to customize your admin panel:
- Custom Views: You can create custom views for your BREAD by overriding Voyager’s default views.
- Custom Routes: Add custom routes in
routes/web.php
if you need additional functionality outside of the BREAD. - Menu Management: You can manage your admin panel’s navigation menu from the Voyager admin panel.
Step 9: Using the Media Manager
Voyager includes a media manager for uploading and managing files. You can access it via Media in the admin panel. You can configure the media settings in config/voyager.php
.
Step 10: User Roles and Permissions
Voyager allows you to manage user roles and permissions:
- Go to Tools > Roles in the admin panel.
- Create roles and assign permissions to each role for managing different parts of the admin panel.
Conclusion
Laravel Voyager simplifies the process of creating an admin panel with a powerful interface for managing your application’s backend. With its built-in features and customizable options, you can quickly set up a robust admin panel for your Laravel application. As you explore Voyager, consider leveraging its extensive documentation for advanced features and customization.