Can't export data using ExportAction with Tenant
I'm trying to export data using Filament Export in my Tenant project, but when I try to export data it ends up giving me this error:
The issue is that this relationship is not what I use, the only relationship that exists between these 2 models is that commonarea belongs to companies, but here it tells me that it needs a relationship, I have reviewed a little more and it seems to me that the export migrations when bringing is causing me problems, I made the change to put it as since customer is the user who is logged in and from his panel he can download the excel, but even so the problem is not solved... is there any idea that me give to solve this problem?
15 Replies
I think that the problem is here:
Any idea guys?
This is the model that i use for export
and this is my Company Model
when i change the foreignId to or other for test i recieve the same error again!
It is as if instead of using the project migration it used the filament package migration at all times
any idea guys?
The problem is on your saving you and saving without the company_id into the export, it looks like you have added company_id to the exports table manually as it doesnt' exist natively. I would recommened removing it or overwrriting the exports model and then apply the company_id by default on save.
That's true, I added it manually because I need to customize certain things, but the problem is not that, the problem is because it keeps asking me for , as I explained above the image I made the change but it keeps asking me for , no longer It is in the migration, therefore the migration that I modified is not taken by filament, I don't know if I understand myself? It seems that it is based more on the migration that comes within the same filament.
Even though the is done and I can modify those migrations, you simply do not take them, which makes me think that no matter how much I modify them to that does not work with user?id it still works with internal migrations.
whatever it requires, but it is understood that when we use tenant the User model of that new panel or the model that extends the User Authentication model is another, I don't know if I understand myself?
Then the problem of the exportAcion and importAcion functionalities are not configured or detailed for tenant and panels in the documentation. I hope you understand my explanation
So it expects user_id by default because that’s the creator and that’s the id of the person creating the row not the company since they are tided to users. If you want to make it a company…. Then you need to override the exporter model and define the user id as a company id etc
Of course it is not the company, out of confusion I put company, but apart from that when I put customer_id it still says that it is missing the user_id, in short Customer is the model of the Company Panel and this extends authenticatable
Well, I will continue testing and analyzing how to solve the problem of both the export and the notifications that I had posted in another problem here, thanks.
This isn’t making much sense sorry, I’m not following.
If you are using
stancl/tenancy
You can put this code inside
Route/tenant.php
inside group just
use Filament\Actions\Exports\Http\Controllers\DownloadExport;
Route::get('filament/exports/{export}/download', DownloadExport::class)
->name('filament.exports.download')
->middleware(['web', 'auth']);
Hey bro, thank you for share!
I'm not using stancl/tenancy, i'm using the filament configuration and implements HasTenants, i'm trying to use all the configuration of Filament, with which I avoid using third-party packages, in fact I have Laravel Excel installed and configured, but I find that the filament functionality for import and export is much more complete and becomes lighter when using jobs for this task.
For what it’s worth, I agree with toeknee. I think you’re overcomplicating by trying to use the company and the user interchangeably which doesn’t make sense in a tenant environment.
If it is true, perhaps the best option is to pass that data to the table, add customer_id and tenant_id to notifications and nothing more... that way I avoid extra work... which does have me a little confused working with extend of the DatabaseNotification class, to show notifications only to the corresponding tenants and customer accounts. Well, I continue to find out and try options but always maintaining the use of filament instead of third-party packages, thanks bro!
Or what would be your recommendation for my case? Do you think it would be a good idea to work with that data in a single table and nothing else?