filament/filament
v3.2.93
v11.9
No response
PHP 8.2
When creating a resource using FilamentPHP, I encountered a namespace collision. Specifically, I created a resource named Form using the command:
php artisan make:filament-resource Form --soft-deletes --view --model --migration --factory
The command completes successfully with the following output:
INFO Migration [database/migrations/2024_07_12_143938_create_forms_table.php] created successfully.
INFO Filament resource [app/Filament/Resources/FormResource.php] created successfully.
However, the generated files contain a namespace conflict. My model's name Form collides with the Filament class Form, causing a fatal error. The error arises in the FormResource.php file due to the following lines:
β use App\Models\Form;
use Filament\Forms;
β use Filament\Forms\Form;
This results in a collision between App\Models\Form and Filament\Forms\Form.
I received the following error message when attempting to use the model:
Symfony\Component\ErrorHandler\Error\FatalError
Cannot use Filament\Forms\Form as Form because the name is already in use
at app/Filament/Resources/FormResource.php:9
5β use App\Filament\Resources\FormResource\Pages;
6β use App\Filament\Resources\FormResource\RelationManagers;
7β use App\Models\Form;
8β use Filament\Forms;
β 9β use Filament\Forms\Form;
10β use Filament\Resources\Resource;
11β use Filament\Tables;
12β use Filament\Tables\Table;
13β use Illuminate\Database\Eloquent\Builder;
Whoops\Exception\ErrorException
Cannot use Filament\Forms\Form as Form because the name is already in use
at app/Filament/Resources/FormResource.php:9
5β use App\Filament\Resources\FormResource\Pages;
6β use App\Filament\Resources\FormResource\RelationManagers;
7β use App\Models\Form;
8β use Filament\Forms;
β 9β use Filament\Forms\Form;
10β use Filament\Resources\Resource;
11β use Filament\Tables;
12β use Filament\Tables\Table;
13β use Illuminate\Database\Eloquent\Builder;
I expected the model to be created and used without namespace conflicts. Ideally, there should be a mechanism to prevent or warn about such collisions to avoid runtime errors. Additionally, the generated files should be error-free to ensure a smooth user experience.
php artisan make:filament-resource Form --soft-deletes --view --model --migration --factory
Attempt to use the resource, checking the FormResource.php file, which will show the conflicting lines.
https://github.com/rvalenzuelaferrada/filamentphp-form-namespace-collision
Symfony\Component\ErrorHandler\Error\FatalError
Cannot use Filament\Forms\Form as Form because the name is already in use
at app/Filament/Resources/FormResource.php:9
5β use App\Filament\Resources\FormResource\Pages;
6β use App\Filament\Resources\FormResource\RelationManagers;
7β use App\Models\Form;
8β use Filament\Forms;
β 9β use Filament\Forms\Form;
10β use Filament\Resources\Resource;
11β use Filament\Tables;
12β use Filament\Tables\Table;
13β use Illuminate\Database\Eloquent\Builder;
Whoops\Exception\ErrorException
Cannot use Filament\Forms\Form as Form because the name is already in use
at app/Filament/Resources/FormResource.php:9
5β use App\Filament\Resources\FormResource\Pages;
6β use App\Filament\Resources\FormResource\RelationManagers;
7β use App\Models\Form;
8β use Filament\Forms;
β 9β use Filament\Forms\Form;
10β use Filament\Resources\Resource;
11β use Filament\Tables;
12β use Filament\Tables\Table;
13β use Illuminate\Database\Eloquent\Builder;
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too