Help for integrating the Laravel package
Forum rules: Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#4302 by spierce
03 Jun 2017, 16:59
I have an existing Laravel 5.4 installation using MariaDB with a custom application running for a site. I want to use Aimeos to add shopping functionality to the site. Is there a way to install without a fresh installation of Laravel? I've tried and can't get it to work.

What I've tried:

Clone production server to create development box.
Change APP_ENV to "development"
Add these lines to composer.json:
Code: Select all    "prefer-stable": true,
    "minimum-stability": "dev",
    "require": {
        "aimeos/aimeos-laravel": "~2017.04",
        ...
    },
    "scripts": {
        ...
        "post-update-cmd": [
            "php artisan vendor:publish --tag=public --force",
            "php artisan vendor:publish",
            "php artisan migrate",
            ...
        ]
    }

Run "composer update"
Install missing php-curl
Run "composer update"
Install missing php-gd
Run "composer update"
Everything downloads and there's an aimeos directory under the vendor directory but the artisan publish and artisan migrate commands don't seem to do anything.

Output from artisan publish command:
Code: Select allCopied Directory [/vendor/laravel/framework/src/Illuminate/Notifications/resources/views] To [/resources/views/vendor/notifications]
Copied Directory [/vendor/laravel/framework/src/Illuminate/Pagination/resources/views] To [/resources/views/vendor/pagination]
Copied Directory [/vendor/laravel/framework/src/Illuminate/Mail/resources/views] To [/resources/views/vendor/mail]
Publishing complete.


Output from artisan migrate command:
Code: Select allNothing to migrate.


As expected from above, look at database structure and no new tables were added. No shop.php in config directory, etc.

I've installed and developed an Aimeos site from scratch on a fresh Laravel install (a couple years ago) but that's not an option with this project. Any way to install without breaking the current site but yet add Aimeos?

Thanks!
Scott
#4303 by aimeos
03 Jun 2017, 20:14
Make sure, you've updated your "./config/app.php" file and added the Aimeos service provider class like described in the docs. Then execute
Code: Select all./artisan aimeos:setup --option=setup/default/demo:1

to create the database tables and the demo data. You can leave out the "--option" part if you want to create only the tables.
#4304 by spierce
04 Jun 2017, 16:38
Thanks! I got the storefront working yesterday but forgot to post here. Currently trying to figure out the admin interface - we already had routes for /admin so we reworked those to not interfere with the Aimeos admin routes. Currently getting

Code: Select allCall to undefined method User::can()


So we're chasing that down today :)
#4305 by spierce
04 Jun 2017, 17:57
We had to make a few tweaks to get things to work with regard to accessing the admin interface. One thing we had to do was change like 291 of the Aimeos Context object to use $user->getName() instead of $user->name

Now we're fighting routing issues. We run multiple sites off the same Laravel install. Our route file looks something like this:

Code: Select all$site1routes = function() {
    Route::get( '/', function() {
        return redirect( '/site1app' );
    }
    Route::group( 'middleware' => [ 'web' ], function() {
        // various routes for site 1
    });
});

Route::group( array( 'domain' => 'site1.com' ), $site1routes );

// repeat above for site 2

$site3apps = function() {
    Route::group( [ 'middleware' => [ 'web' ] ], function() {
        Route::get( 'login', [ 'as' => 'login', 'uses' => function() {
            return view( 'login' );
        }]);

        Route::post( 'auth/login', [ 'as' => 'auth.login', 'uses' => function( \Illuminate\Http\Request $request ) {
            if( \Auth::attempt([
                'email' => $request->get( 'email' ),
                'password' => $request->get( 'password' )
            ])) {
                return redirect( '/site3admin' );  // changed from /admin for adding Aimeos
            } else {
                return view( 'login' )->withErrors( array( 'message' => 'The Email/password provided do not match.' ) );
            }
          }]);

          Route::get( 'logout', [ 'as' => 'logout', 'uses' => function() {
              \Auth::logout();
              \Session::flush();
              return redirect( 'login' );
          }]);

        Route::group( [ 'middleware' => [ 'auth', 'web' ] ], function() {
            // various site3 admin routes, all changed from /admin/path to /site1admin/path for adding Aimeos
        });
    });
};

Route::group( array( 'domain' => 'site3.com' ), $site3routes );


Only site3 needs authentication so that's how we set it up. We don't want the login form displayed on the other sites, etc. To try and get Aimeos working, we commented out all of our login and logout routes, and added
Code: Select allAuth::routes()
to the top of routes/web.php but we still can't get authorization working with Aimeos.

We previously had
Code: Select all$redirectTo="/site3admin";
in the LoginController but we removed that as well. We also tried changing it to
Code: Select all$redirectTo="/admin";
but still not working.

When we access /admin, we see the Aimeos login form. When we try to login, we get
Code: Select allNotFoundHttpException in RouteCollection.php
. We even created a brand new user using php artisan
Code: Select allaimeos:account email@ite.com --admin
to make sure the user had admin authority. No luck.

Any ideas?
#4306 by aimeos
04 Jun 2017, 22:15
spierce wrote:Thanks! I got the storefront working yesterday but forgot to post here. Currently trying to figure out the admin interface - we already had routes for /admin so we reworked those to not interfere with the Aimeos admin routes.


You can reconfigure the admin routes (and all others as well) to use a different prefix, domain, etc.
- https://github.com/aimeos/aimeos-laravel/blob/master/src/routes.php#L3
- https://github.com/aimeos/aimeos-laravel/blob/master/src/config/shop.php#L6

Code: Select allreturn [
   'routes' => [
      'login' => ['prefix' => 'aimeos', 'middleware' => ['web']],
      'jqadm' => ['prefix' => 'aimeos/admin/{site}/jqadm', 'middleware' => ['web', 'auth']],
      'extadm' => ['prefix' => aimeos/'admin/{site}/extadm', 'middleware' => ['web', 'auth']],
      'jsonadm' => ['prefix' => 'aimeos/admin/{site}/jsonadm', 'middleware' => ['web', 'auth']],
   ],
   // ...
];