Laravel/Setup admin interface

From Aimeos documentation

Laravel
Other languages:
English 100%

To use the admin interface, you have to set up Laravel authentication first. Please follow the Laravel documentation to create the necessary code:

You need a route for /login in Laravel 5.1 too!

Test if your authentication setup works before you continue. Create an admin account for your Laravel application so you will be able to log into the Aimeos admin interface:

php artisan aimeos:account <email> --admin

The e-mail address is the user name for login and the account will work for the frontend too. To protect the new account, the command will ask you for a password.

As a last step, you need to extend the boot() method of your App\Providers\AuthServiceProvider class and add the lines to define how authorization for "admin" is checked.

For Laravel 5.3/5.4/5.5/5.6 and Aimeos 2017.x/2018.x use:

  1. public function boot()
  2. {
  3.     // Keep the lines before
  4.  
  5.     Gate::define('admin', function($user, $class, $roles) {
  6.         if( isset( $user->superuser ) && $user->superuser ) {
  7.             return true;
  8.         }
  9.         return app( '\Aimeos\Shop\Base\Support' )->checkUserGroup( $user, $roles );
  10.     });
  11. }

For Laravel 5.1/5.2 and Aimeos 2016.x you have to use instead:

  1. public function boot(GateContract $gate)
  2. {
  3.     // ...
  4.  
  5.     $gate->define('admin', function($user, $roles) {
  6.         return app( '\Aimeos\Shop\Base\Support' )->checkGroup( $user->id, $roles );
  7.     });
  8. }

If you've still started the internal PHP web server (php -S 127.0.0.1:8000 -t public) you should now open this URL in your browser:

http://127.0.0.1:8000/index.php/admin

Enter the e-mail address and the password of the newly created user and press "Login". If you don't get redirected to the admin interface (that depends on the authentication code you've created according to the Laravel documentation), point your browser to the /admin URL again.

Make sure that you aren't already logged in as a non-admin user! In this case, login won't work because Laravel requires to log out first.


<< Previous: Test the installation | Next: Configure the cronjobs >>