Laravel 5.4 with Backpack

12.06.2017

1. Install Laravel 5.4

Use the steps in the Laravel Documentation. Most likely it's running:

composer create-project --prefer-dist laravel/laravel yourprojectname

Remember to:

  • "chmod -R o+w" the storage and bootstrap/cache directories
  • enter your database information in the .env file

You may need to generate a key

If you've chosen NOT to install Laravel using the steps above, and you've done it using laravel new yourprojectname, remember you need to generate a key, using php artisan key:generate

2. Install BackpackBase

1) Run in your terminal:

cd yourprojectname
composer require backpack/base

2) Add the service providers in config/app.php, at the end of the providers array:

/*
* Backpack Service Providers...
*/
BackpackBaseBaseServiceProvider::class,

3) Then run a few commands in the terminal:

php artisan vendor:publish --provider="BackpackBaseBaseServiceProvider" #publishes configs, langs, views and AdminLTE files
php artisan vendor:publish --provider="PrologueAlertsAlertsServiceProvider" # publish config for notifications - prologue/alerts
php artisan migrate #generates users table (using Laravel's default migrations)

4) Make sure the reset password emails have the correct reset link by adding these to your User model:

  • before class name:
use BackpackBaseappNotificationsResetPasswordNotification as ResetPasswordNotification;
  • as a method inside the User class:
 /**
 * Send the password reset notification.
 *
 * @param string $token
 * @return void
 */
 public function sendPasswordResetNotification($token)
 {
 $this->notify(new ResetPasswordNotification($token));
 }

5) [optional] Backpack comes with a generators package that helps you create models, controllers, requests, etc from the command line. laracasts/generators is an awesome package you can use to generate migrations. Install them only if you want (for your local environment only - that's why the --dev flag). But using them can greatly improve your speed:

composer require backpack/generators --dev
composer require laracasts/generators --dev

laracasts/generators compatibility with Laravel 5.4

As of 03 Feb 2017, laracasts/generators is not officially compatible with L5.4. We have submitted the fixes, they've been merged, they work perfectly, but they haven't been officially published. For now, you can install laracasts/generators on L5.4 by:

1) manually specifying this in your composer.json file, in the require-dev section:

 "laracasts/generators": "dev-master as 1.1.4",

2) then running composer update

6) [optional] Change values in config/backpack/base.php to make the admin panel your own. Backpack is white label, so you can change everything: menu color, project name, developer name etc.

7) [optional] If your application only has one login screen (for the admins), that means you're not going to use the auth controllers that Laravel provided by default. You're only going to use Backpack's auth controllers. You can keep the Laravel ones in your project, of course. But some people like to delete them to not get confused later on:

# OPTIONAL! Please read the notice above.
rm -rf app/Http/Controllers/Auth #deletes laravel's demo auth controllers

3. Install BackpackCRUD

1) In your terminal:

composer require backpack/crud

2) Add this provider to your config/app.php, after "base":

 BackpackCRUDCrudServiceProvider::class,

3) Run these command in this exact order:

php artisan elfinder:publish #published elfinder assets
php artisan vendor:publish --provider="BackpackCRUDCrudServiceProvider" --tag="public" #publish CRUD assets
php artisan vendor:publish --provider="BackpackCRUDCrudServiceProvider" --tag="lang" #publish CRUD lang files 
php artisan vendor:publish --provider="BackpackCRUDCrudServiceProvider" --tag="config" #publish CRUD and custom elfinder config files
php artisan vendor:publish --provider="BackpackCRUDCrudServiceProvider" --tag="elfinder" #publish custom elFinder views

4) Define an 'uploads' disk. In your config/filesystems.php add this disk:

'uploads' => [
 'driver' => 'local',
 'root' => public_path('uploads'),
 ],

5) Create "uploads" folder in your public folder.

6) [Optional] You can now add the file manager to the menu, in resources/views/vendor/backpack/base/inc/sidebar.blade.php or menu.blade.php:

<li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/elfinder') }}"><i class="fa fa-files-o">i> <span>File managerspan>a>li>

---- OPTIONALS ----

Everything else is optional. Your project might use them or it might not. Only do each following step if you need the functionality that package provides.

4. Install BackpackLangFileManager [optional]

>> See screenshots and installation

Step 1. Install via Composer

composer require backpack/langfilemanager

Step 2. Add the service provider

In your config/app.php, add this to the providers array:

BackpackLangFileManagerLangFileManagerServiceProvider::class,

Step 3. Run the migration, seed and file publishing

php artisan migrate --path=vendor/backpack/langfilemanager/src/database/migrations
php artisan db:seed --class="BackpackLangFileManagerdatabaseseedsLanguageTableSeeder"
php artisan vendor:publish --provider="BackpackLangFileManagerLangFileManagerServiceProvider" --tag="config" #publish the config file
php artisan vendor:publish --provider="BackpackLangFileManagerLangFileManagerServiceProvider" --tag="lang" #publish the lang files

Step 4. [Optional] You can now add it to the menu, in resources/views/vendor/backpack/base/inc/sidebar.blade.php or menu.blade.php:

<li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/language') }}"><i class="fa fa-flag-o">i> <span>Languagesspan>a>li>
<li><a href="{{ url(config('backpack.base.route_prefix', 'admin') . '/language/texts') }}"><i class="fa fa-language">i> <span>Language Filesspan>a>li>

5. Install BackpackBackupManager [optional]

>> See screenshots and installation

1) In your terminal

composer require backpack/backupmanager

2) Then add the service providers to your config/app.php file:

SpatieBackupBackupServiceProvider::class,
BackpackBackupManagerBackupManagerServiceProvider::class,

3) Publish the config file and lang files:

php artisan vendor:publish --provider="BackpackBackupManagerBackupManagerServiceProvider"

4) Add a new "disk" to config/filesystems.php:

 // used for Backpack/BackupManager
 'backups' => [
 'driver' => 'local',
 'root' => storage_path('backups'), // that's where your backups are stored by default: storage/backups
 ],

This is where you choose a different driver if you want your backups to be stored somewhere else (S3, Dropbox, Google Drive, Box, etc).

5) [optional] Add a menu item for it in resources/views/vendor/backpack/base/inc/sidebar.blade.php or menu.blade.php:

<li><a href="{{ url(config('backpack.base.route_prefix', 'admin').'/backup') }}"><i class="fa fa-hdd-o">i> <span>Backupsspan>a>li>

6) [optional] Modify your backup options in config/laravel-backup.php

7) [optional] Instruct Laravel to run the backups automatically in your console kernel:

// app/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
 $schedule->command('backup:clean')->daily()->at('04:00');
 $schedule->command('backup:run')->daily()->at('05:00');
}

8) [optional] If you need to change the path to the mysql_dump command, you can do that in your config/database.php file. For MAMP on Mac OS, add these to your mysql connection:

 'dump_command_path' => '/Applications/MAMP/Library/bin/', // only the path, so without 'mysqldump' or 'pg_dump'
 'dump_command_timeout' => 60 * 5, // 5 minute timeout
 'dump_using_single_transaction' => true,

6. Install BackpackLogManager [optional]

>> See screenshots and installation

1) Install via composer:

composer require backpack/logmanager

2) Then add the service provider to your config/app.php file:

 BackpackLogManagerLogManagerServiceProvider::class,

3) Add a "storage" filesystem in config/filesystems.php:

// used for Backpack/LogManager
'storage' => [
 'driver' => 'local',
 'root' => storage_path(),
 ],

4) [Optional] Configure Laravel to create a new log file for every day, in your .ENV file, if it's not already. Otherwise there will only be one file at all times.

 APP_LOG=daily

or directly in your config/app.php file:

 'log' => env('APP_LOG', 'daily'),

5) [Optional] Publish the lang files if you think you'll need to modify them.

 php artisan vendor:publish --provider="BackpackLogManagerLogManagerServiceProvider"

6) [optional] Add a menu item for it in resources/views/vendor/backpack/base/inc/sidebar.blade.php or menu.blade.php:

<li><a href="{{ url(config('backpack.base.route_prefix', 'admin').'/log') }}"><i class="fa fa-terminal">i> <span>Logsspan>a>li>

7. Useful CRUD: BackpackSettings [optional]

An interface for the administrator to easily change application settings. Uses Laravel Backpack.

>> See screenshots and installation

1) In your terminal:

composer require backpack/settings

2) Add the service provider to your config/app.php file:

BackpackSettingsSettingsServiceProvider::class,

3) Run the migration and add some example settings:

php artisan vendor:publish --provider="BackpackSettingsSettingsServiceProvider"
php artisan migrate
php artisan db:seed --class="BackpackSettingsdatabaseseedsSettingsTableSeeder"

4) [Optional] Add a menu item for it in resources/views/vendor/backpack/base/inc/sidebar.blade.php or menu.blade.php:

<li><a href="{{ url(config('backpack.base.route_prefix', 'admin').'/setting') }}"><i class="fa fa-cog">i> <span>Settingsspan>a>li>

8. Useful CRUD: BackpackPageManager [optional]

>> See screenshots and installation

1) In your terminal

composer require backpack/pagemanager

2) Then add the service providers to your config/app.php file:

CviebrockEloquentSluggableServiceProvider::class, 
BackpackPageManagerPageManagerServiceProvider::class,

3) Publish the views, migrations and the PageTemplates trait:

php artisan vendor:publish --provider="BackpackPageManagerPageManagerServiceProvider"

4) Run the migration to have the database table we need:

php artisan migrate

5) [optional] Add a menu item for it in resources/views/vendor/backpack/base/inc/sidebar.blade.php or menu.blade.php:

<li><a href="{{ url(config('backpack.base.route_prefix', 'admin').'/page') }}"><i class="fa fa-file-o">i> <span>Pagesspan>a>li>

9. Useful CRUD: BackpackPermissionManager [optional]

An admin panel for user authentication on Laravel 5, using BackpackCRUD. Add, edit, delete users, roles and permission.

>> Installation
>> Github

10. Useful CRUD: BackpackMenuCRUD [optional]

An admin panel for menu items on Laravel 5, using BackpackCRUD. Add, edit, reorder, nest, rename menu items and link them to BackpackPageManager pages, external link or custom internal link.

>> Github

11. Useful CRUD: BackpackNewsCRUD [optional]

Since NewsCRUD does not provide any extra functionality other than BackpackCRUD, it is not a package. It's just a tutorial to show you how this can be achieved. In the future, CRUD examples like this one will be easily installed from the command line, from a central repository. Until then, you will need to manually create the files.

>> Github

loading