Skip to content

ChristianBraybrooke/Laravel-ECommerce

Repository files navigation

Laravel ECommerce Package

Laravel Setup

laravel new laravel-shop
php artisan make:auth

Installation

Only installation on a fresh Laravel app is reccomended:

composer require chrisbraybrooke/laravel-ecommerce

Setup:

php artisan vendor:publish --tag=migrations

php artisan vendor:publish --tag=ecommerce-config
php artisan vendor:publish --tag=ecommerce-migrations
php artisan vendor:publish --tag=ecommerce-admin

php artisan migrate

Roles And Permissions:

php artisan vendor:publish --tag=ecommerce-seeds

In database/seeds/DatabaseSeeder.php add the RolesAndPermissionsSeeder class

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // $this->call(UsersTableSeeder::class);
        $this->call(RolesAndPermissionsSeeder::class)
    }
}

And then seed the database

php artisan migrate --seed

Media:

php artisan vendor:publish --tag=config

After publishing the config files, be sure to change the media class to ChrisBraybrooke\ECommerce\Models\Media

/*
 * The class name of the media model that should be used.
 */
 'media_model' => ChrisBraybrooke\ECommerce\Models\Media::class,

Users:

To ensure all roles / permissions work correctly, you will need to edit your App/User.php class so that it extends the Laravel Ecommerce User class.

use Illuminate\Notifications\Notifiable;
use ChrisBraybrooke\ECommerce\Models\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
}

You will then want to create your first admin user.

php artisan tinker

$user = new App\User
$user->name = 'Your Name'
$user->email = 'youremail@here.com'
$user->password = bcrypt('password')

$user->save()

$user->assignRole('admin')

We use Laravel Passport under the hood, so make sure you install passport to generate the relevent keys etc.

php artisan passport:install

You then need to add this middleware to your app/Http/Kernel.php web group. Make sure it is added after the \App\Http\Middleware\EncryptCookies::class middleware.

'web' => [
    // Other middleware...
    \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
],

Finally in your config/auth.php config file, you should set the API driver to passport.

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],

Updating the version

It's a good idea to keep the version numbering up-to-date with any minor and major changes that are made to avoid conflicts with older code. This package uses seperate version numbers for its API and SPA functions.

The API version number can be found and changed under src/ECommerceServiceProvider.php And the SPA version number can be found and changed under resources/assets/admin-spa/admin.js (this one will require compiling).