Build a fullstack admin app with Voyager in 5 minutes
Laravel is an incredible framework built by Taylor Otwell that combines powerful web development features, extensive documentation and an active community. In this tutorial we are going to build a fullstack application complete with an admin panel and user management.Special thanks to The Control Group for building Voyager, an open source admin tool for Laravel.
Minute 1: Create the Laravel application
I'm going to assume you have Laravel and MySQL installed for the purposes of this tutorial. I wrote a short shell script for creating Laravel applications available here if you are not familiar with the commands or interested in saving yourself time.
Minute 2: Generate a Database
Create a MySQL database and set your environment variables. You will need to know the MySQL username and password for your dev machine. The commands below should help:
$ mysql -uroot -p
MySQL [(none)]> create database NAME_OF_YOUR_APP;
I also recommend Sequel Pro for visualizing records and tables within the database we created.
Minute 3: Set your environment variables
The first shell script to create the Laravel application created a .env file. Open up the project in Sublime Text or your editor of choice and edit the .env files so that our Laravel application can connect to the database we set up.
APP_URL=localhost:8000
DB_HOST=localhost
DB_DATABASE=THE_NAME_OF_DATABASE_YOU_CREATED
DB_USERNAME=THE_MYSQL_DATABASE_USERERNAME_ON_YOUR_MACHINE
DB_PASSWORD=THE_MYSQL_DATABASE_PASSWORD_ON_YOUR_MACHINE
We need to clear out the configuration cache so that Laravel can update the application with the new values. Additionally, we need to run our database migrations to create the tables and columns for MySQL. Migrations in Laravel applications are in database/migrations.
php artisan config:clear
php artisan migrate
Minute 4: Install and Configure Voyager
Use Composer to install Voyager: composer require tcg/voyager
Add the Voyager pachage to our list of supported Package Service Providers. This list is in config/app.php.
'providers' => [
// Laravel Framework Service Providers...
//...
// Package Service Providers
TCG\Voyager\VoyagerServiceProvider::class,
// ...
// Application Service Providers
// ...
],
You'll now have access to a voyager artisan command that will generate all of the required files for a state of the art admin dashboard. Run that command.
$ php artisan voyager:install --with-dummy
Minute 5: Log into your Admin dashboard to check it out!
Start your application with php artisan serve
and then head to http://localhost:8000/admin. Use the default credentials admin@admin.com / password
to login.
Congrats you did it! Check out Voyager's amazing features by reading the docs or checking out the video tutorials below.
Thanks for reading! If you enjoyed the article give me a shout on twitter or you can support the Voyager project directly by issuing a PR or giving it a star on github.
Please Help Me Dear Laravel Experts.
Laravel Voyager Admin Dashboard Page Show Blank After Adding PagesController In Route Page.
My Route Script:
<?php
Route::get(’/’, function () {
return view(‘welcome’);
});
Route::get(’{slug}’, ‘PagesController@show’);
Route::group([‘prefix’ => ‘admin’], function () {
Voyager::routes();
});
My PagesController Script:
<?php
namespace App\Http\Controllers;
use App\Page;
use Illuminate\Http\Request;
class PagesController extends Controller
{
public function show($slug)
{
$page = Page::findBySlug($slug);
return view(‘about’, [‘page’ => $page]);
}
My Page Model Script:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Page extends Model
{
public static function findBySlug($slug)
{
return static::where(‘slug’, $slug)->first();
}
And My View Page Script:
<html>
<head>
<title>{{ $page[‘title’] }}</title>
</head>
<body>
</body>
</html>