F
Filament6mo ago
Tieme

Error on creating resource with custom --model-namespace

Hi All, I want to create a resource with following command php artisan make:filament-resource Customer --generate --soft-deletes --view --model-namespace=App\\Models\\Team as documented here https://filamentphp.com/docs/3.x/panels/resources/getting-started#specifiying-a-custom-model-namespace This throws me a Fatal error :
PHP Fatal error: Cannot declare class App\Models\Team\Customer, because the name is already in use in C:\Users\***\PHPStormProjects\***\app\Models\Team\Customer.php on line 14

Symfony\Component\ErrorHandler\Error\FatalError

Cannot declare class App\Models\Team\Customer, because the name is already in use

at app\Models\Team\Customer.php:14
10▕ use Illuminate\Database\Eloquent\Model;
11▕ use Illuminate\Database\Eloquent\Relations\BelongsTo;
12▕ use Illuminate\Database\Eloquent\SoftDeletes;
13▕
➜ 14▕ class Customer extends Model
15▕ {
16▕ use BelongsToTeam;
17▕ use HasFactory;
18▕ use HasUserStamps;


Whoops\Exception\ErrorException

Cannot declare class App\Models\Team\Customer, because the name is already in use

at app\Models\Team\Customer.php:14
10▕ use Illuminate\Database\Eloquent\Model;
11▕ use Illuminate\Database\Eloquent\Relations\BelongsTo;
12▕ use Illuminate\Database\Eloquent\SoftDeletes;
13▕
➜ 14▕ class Customer extends Model
15▕ {
16▕ use BelongsToTeam;
17▕ use HasFactory;
18▕ use HasUserStamps;

1 vendor\filp\whoops\src\Whoops\Run.php:514
Whoops\Run::handleError("Cannot declare class App\Models\Team\Customer, because the name is already in use", "C:\Users\***\PHPStormProjects\***\app\Models\Team\Customer.php")

2 [internal]:0
Whoops\Run::handleShutdown()
PHP Fatal error: Cannot declare class App\Models\Team\Customer, because the name is already in use in C:\Users\***\PHPStormProjects\***\app\Models\Team\Customer.php on line 14

Symfony\Component\ErrorHandler\Error\FatalError

Cannot declare class App\Models\Team\Customer, because the name is already in use

at app\Models\Team\Customer.php:14
10▕ use Illuminate\Database\Eloquent\Model;
11▕ use Illuminate\Database\Eloquent\Relations\BelongsTo;
12▕ use Illuminate\Database\Eloquent\SoftDeletes;
13▕
➜ 14▕ class Customer extends Model
15▕ {
16▕ use BelongsToTeam;
17▕ use HasFactory;
18▕ use HasUserStamps;


Whoops\Exception\ErrorException

Cannot declare class App\Models\Team\Customer, because the name is already in use

at app\Models\Team\Customer.php:14
10▕ use Illuminate\Database\Eloquent\Model;
11▕ use Illuminate\Database\Eloquent\Relations\BelongsTo;
12▕ use Illuminate\Database\Eloquent\SoftDeletes;
13▕
➜ 14▕ class Customer extends Model
15▕ {
16▕ use BelongsToTeam;
17▕ use HasFactory;
18▕ use HasUserStamps;

1 vendor\filp\whoops\src\Whoops\Run.php:514
Whoops\Run::handleError("Cannot declare class App\Models\Team\Customer, because the name is already in use", "C:\Users\***\PHPStormProjects\***\app\Models\Team\Customer.php")

2 [internal]:0
Whoops\Run::handleShutdown()
How can i handle custom model namespace ? i already have tried --model-namespace=App\\Models\\Team\\Customer this wil create the resource, only not generate all the fields for me and also namespace is wrong.
1 Reply
Tieme
Tieme6mo ago
The workaround for now is moving the model to App/Models and don't use the --model-namespace= And than moving it back to my Team folder/namepsace and change the model namespace in resource But if anyone know wat i'm doing wrong i would really want to know the solution.