venturedrake / laravel-crm-starter

Install and setup a complete Laravel CRM application
https://laravelcrm.com
MIT License
14 stars 15 forks source link

New Install Optimize Error #7

Open ben-norton opened 1 month ago

ben-norton commented 1 month ago

Successfully installed a brand new copy of the application using the instructions provided here: https://laravelcrm.com/docs/quickstart.html#installation. Immediately following installation, I ran the command: php artisan optimize Returned the following error:

INFO Caching the framework bootstrap files.

config ........................................................................................................... 8ms FAIL

ErrorException

Cannot declare class App\User, because the name is already in use

at ..\laravel-crm\vendor\venturedrake\laravel-crm\src\LaravelCrmServiceProvider.php:207 203▕ { 204▕ Paginator::useBootstrap(); 205▕ 206▕ if ((app()->version() >= 8 && class_exists('App\Models\User')) || (class_exists('App\Models\User') && ! class_exists('App\User'))) { ➜ 207▕ class_alias(config("auth.providers.users.model"), 'App\User'); 208▕ if (class_exists('App\Models\Team')) { 209▕ class_alias('App\Models\Team', 'App\Team'); 210▕ } 211▕ }

1 ...\laravel-crm\vendor\venturedrake\laravel-crm\src\LaravelCrmServiceProvider.php:207 class_alias()

2 ..\laravel-crm\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36 VentureDrake\LaravelCrm\LaravelCrmServiceProvider::boot()

Windows 11 Apache 2.4 PHP 8.2

andrewdrake commented 1 month ago

I have noticed this, it is there so the package can support the User class being in App folder or App\Models. Laravel 8 or less did not use a Models folder.

It does however seem to throw that error when running optimize.

I will be looking to fix this with a better approach to support the different User class locatin

ben-norton commented 1 month ago

I recommend dropping support for installations that place Models outside the models folder. I started using a separate folder for models with 5.8 (I think). It's their home and they need a home. Free range models are a problem. Chances are that if someone is using an older version with models stored under App, they've run into similar issues elsewhere, probably multiple times.

andrewdrake commented 1 month ago

Yes I agree they should be in the Models folder, however unfortunately there will be many projects that have models in the App folder, as it was the default setup. This can also mean that legacy projects that have been upgraded may still retain that structure. I have worked on several projects where that is the case, some are on Laravel 11 now. The work involved in moving models to the models folder is not worth the time.

ben-norton commented 1 month ago

Great point Andrew. I should have made that connection. Models are not required to be in the Models folder. Therefore, projects created prior to 9 will most likely keep them in App.