dynamic model

Hi All I am wondering if you can help me, I am building a custom page, the custom data is working fine however when I try and do an Action::make it trys to get it from the default table for the model like it is set before mounting below is my page for the custom logic, the table data itself is filled out and working however the error I get is php SQLSTATE[42S02]: Base table or view not found: 1146 Table 'tenantfoo.user_datasets' doesn't exist I cant include the whole file because of discord limits, if you want the rest let me know but it builds the form correctly. the $dynamicTableName property on the UserDataSet just sets the table in the constructor. ```php public function mount(int|string $record): void { $this->record = Dataset::where('id', $record)->first(); UserDataSet::$dynamicTableName = "ds" . $this->record->table_name; $this->dataSet = UserDataSet::all(); static::authorizeResourceAccess(); } public function table(Table $table): Table { return $table->columns($this->getFormSchema()) ->query(UserDataSet::query()) ->headerActions([ \Filament\Tables\Actions\Action::make('create') ->form([ TextInput::make('name')->label('Name') ])->action(function (array $data, UserDataSet $record): void { dd($data); })->mountUsing(function () { dd('hello'); }) ]); } } ```
5 Replies
awcodes
awcodesβ€’12mo ago
Definitely going to need to see the full code. This is a non typical setup. πŸ™‚ Also, make sure your are calling parent::mount() too if this is a standard resource. Seems odd too, that you are calling getFormSchema() in the columns() modifier.
DrByte
DrByteβ€’12mo ago
I cant include the whole file because of discord limits,
https://gist.github.com is the ideal way to share the larger blocks of code, even multiple files.
Gist
Discover gists
GitHub Gist: instantly share code, notes, and snippets.
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
Hi Both, Sorry for the late reply, I have updated my code a bit but it's still not working, I am using LaracraftTech\LaravelDynamicModel now with regards to the getFormSchema this was left over from another class that i just havent renamed as of yet, https://gist.github.com/sabuto/f4003a422389fbb11dffc5af0eb88969 when i click the action button I get model not found it is almost as if it is trying to use the model class and not the variable
Gist
Dynamic Models
Dynamic Models. GitHub Gist: instantly share code, notes, and snippets.
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
bump Asking again incase anyone knows bumping bump
Want results from more Discord servers?
Add your server