Automatically generating forms and tables not working?
https://filamentphp.com/docs/3.x/panels/resources/getting-started#automatically-generating-forms-and-tables
i do:
but i get it all empty, while i expected to have automatically the fields prepared on form and table (and yes, my transaction table has fields, migrations have been ran, etc):
Solution:Jump to solution
In your models table name, you have prefixed it with a database prefix:
bgpay
This is the cause. You should set the mysql connection to have a prefix if the table does within the .env...
34 Replies
Do you have a model: Transaction and a database table transaction?
yes both
i already have records actually
i already faced this issue months ago and wasnt able to find what was happening
maybe you need
doctrine/dbal
package?no, since ive already created other resources and just worked
also just checked composer, i have it installed
i just dont understand what is going on, since it doesnt work but doesnt tell errors or what could be happening
bump
Are you sure there isn't any case issues with naming and they are in the root of the models directory
they are in the root of the models directory
and wdym about the case issues? the $casts array? @toeknee
case i.e. Transaction::class vs transaction::class
hmm, i use the default conventions for naming classes, models, migrations
not sure if u mean this
well, im gonna do a repo just to test it individually, lets see what happens
okay @toeknee i've created this repo - https://github.com/ericmp33/test-filament
it has 4 simple commits:
1-install laravel
2-install filament
3-create Transaction model & migration
4-add transactions relationship to User model
next step is just doing:
in my case i get it all empty
im missing something?
(yes, ive ran the migrations)
if u want u can clone it and test it (if u want 🙌 )
Wiull do
Quick Q have you tested on Laravel 10?
noup, only in L11
but weeks ago this same issue happened to me in a L10 app, where i wasnt able to create a filament resource with
--generate
flagYou have caused it
howwww
Solution
In your models table name, you have prefixed it with a database prefix:
bgpay
This is the cause. You should set the mysql connection to have a prefix if the table does within the .env
oh my bad, that wasnt suposed to be there 🤦
let me review it & ill try again
Nope as it doesn't exist in the migration.
so remove all prefixes and it'll generate just fine.
you might need to manually install dbal too, if you haven't. L11 completely removed its dependancy on the package. https://laravel.com/docs/11.x/upgrade#doctrine-dbal-removal
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
No it's part of the install already 🙂
👍 just pointing it out.
okay now works
so doesnt support multiple database connections? or how?
because this repo test comes from an app with multiple databases sharing a common db storing the users
that is why i had those prefixes
cuz i have multiple db connections
but for the test i just setup one, without the others
IT will do yes, but not as a table name
You would need to add the prefix to the database connection with a prefix .env
Just create different connection types for each connection
mysql_1
mysql_2
mysql_3
all with their own .env constants.
I do it for multiple databases across multiple database types.
but i already have the connections in database laravel config file & in .env
Then set the prefix in there?
example:
like this is ok?
not sure wdym by prefix
Yes, it is. but you don't have the prefix if you are using prefixes
So there is no env for prefix, so just add it if they have prefixs
ohhh
so u mean to add in there:
'prefix' => 'bgpay'
and in the forms one:
'prefix' => 'forms'
etc
the file is
config/database.php
right?
i tried it like this but still doesnt generate it, im doing something wrong?
but im not using prefixes, doing this -> protected $table = 'bgpay.transactions';
i was just defining that the database from where the table transactions
belongs to, no?
a prefix would be protected $table = 'bgpay_transactions';
but is a dot, with a dot is still a prefix?So if no prefixes no need to use them and no need for a dot. The bgpay you just need to set the MySQL connection. mysql, mysql_bgpay
Then clone MySQL in database.php config snd name it mysql_bgpay?
i do need to define the
$table
attribute like that, otherwise i'm unable to do relationships between models of diferent dbs
in each model i define the $connection
& the $table
both needed in this case
otherwise, when calling relations it tries to search the table on same database, but the related model may be in other database table, so that is why i need the $table
attribute with the database name and then the dot and then the table name
with this setup, i guess filament cant figure out how to generate the resources or idk how to tell filament to do so
in the demo project i created, yeah it works cuz i dont have this multiple db setupSo if you define connection and table you don't need to dot prefix the table? You just use natively relationships between the models.
Else if you were happy with how it was working less the generate, just do it that way and don't use generate.
okay then yeah, i dont need prefixes. not sure why u suggested it but might be useful for other cases, not sure
Because you had a dot notation in your code as if it was a prefix
where?
yeah, i think ill do this for now and generate it by myself yeah no prob 🦾
in the table name originally
hmmm i dont think so, i was just using
protected $table = 'bgpay.transactions';
with the dot
well nvm dont worry
thanks for the help