vanilophp / framework

The truly Laravel E-commerce Framework
https://vanilo.io
MIT License
810 stars 102 forks source link

Issue with extending or implementing User with Vanilo, Laravel 8 #90

Closed tobyl closed 3 years ago

tobyl commented 3 years ago

Hello, I have a fresh install of Laravel 8 and I'm trying to get Vanilo running (I understand that version 8 isn't fully supported yet).

After following the instructions, I see the error:

Class App\User must extend or implement Konekt\User\Contracts\User.

I have tried both the simple and flexible methods.

In my composer.json:

"vanilo/framework": "^2.0"

My User model:

<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends \Konekt\AppShell\Models\User
{
    use HasFactory, Notifiable;

    ...

I have also tried Konekt\User\Contracts\User as the path to extend.

Any guidance greatly appreciated!

fulopattila122 commented 3 years ago

A small note regarding 2.0: all the modules are stable 2.0.0, the Framework layer isn't stable yet, but it is in a working state (I'm also working with it right now on a project).

As far as I see the problem in your case is that you apparently have both App\Models\User and App\User. Can you check that?

tobyl commented 3 years ago

Thank you for the response! It's a fresh install of laravel 8 with no modifications done other than what was required to install Vanilo, there is a single model at app/Models/User.php. I "believe" that I had enabled the built in auth and it worked before doing the modifications for Vanilo.

Edit: Apologies, just noticed a typo in the original post - the first line of the User class is inaccurate, it was the lines recommended in the Vanilo docs - I tried both simple and flexible methods.

fulopattila122 commented 3 years ago

Do you use the correct class in the AppServiceProvider::boot method?

If your app's user model is App\Models\User, then you need to tell concord to use that model:

$this->app->concord->registerModel(\Konekt\User\Contracts\User::class, \App\Models\User::class);
tobyl commented 3 years ago

Ah, that was it - thank you so much for this, I'm still learning how a lot of these pieces fit together!

fulopattila122 commented 3 years ago

This Concord "register model" thingy is basically an alternative solution to the configuration based model replacement.

Examples of the configuration based model replacement:

Concord proxies can do a bit more than that, but those features are rather useful for package developers.

If you're only developing your application, then consider the registerModel() call as a "do it once forget it afterwards" way that tells the underlying libraries that your application is using the given model.

samuelrojasp commented 3 years ago

Do you use the correct class in the AppServiceProvider::boot method?

If your app's user model is App\Models\User, then you need to tell concord to use that model:

$this->app->concord->registerModel(\Konekt\User\Contracts\User::class, \App\Models\User::class);

then in the docs it should be noted that in case of a fresh laravel 8 install this should be in the boot method..

fulopattila122 commented 3 years ago

It's noted in the docs :wink: https://vanilo.io/docs/2.x/installation#step-3-register-the-model

samuelrojasp commented 3 years ago

It only says about App\User but not App\Models\User