Creating new record produces error
i created a resource from a pivot model in my filament admin panel.
so my model definition is like this:
when i create a new record, after submitting the form, i get:
Missing required parameter for [Route: filament.admin.resources.user-song-play-histories.edit] [URI: admin/user-song-play-histories/{record}/edit] [Missing parameter: record].
if my model definition is like this:
i get no error
but the model represents a pivot table, what should i do? why this happens?
is the problem that ive created a resource from a pivot model, is this expected?8 Replies
anyone ? (:
Again, on my phone. First question would be if your pivot model has a primary key. If you want to use it as a resource it should have one, else it won’t know which record to edit.
👋 hii
the pivot has this structure
Sorry, went offline for a little bit. Did you set up incremnting for the pivot model? Explained here: https://laravel.com/docs/10.x/eloquent-relationships#custom-pivot-models-and-incrementing-ids
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.
This makes sure an id is returned when creating a record, which can then be passed to the edit route.
but i mean, i thought that this was set by default to be incrementing to true
and it does, i mean, it auto increments
nah, its fine, i have been offline too
ill try to set that up lets see if it fixes it
crazy
it works now
as u said
adding:
thanks a lot
should i add it to all my pivots? 🤔
I think when you are creating them by attaching models you don’t need them. But if you create them as separate model you do. Often you create those pivots by have a relation manager on a certain resource. So basically you only need it when you create a resource for the pivot model I guess.
oh i understand, yeah makes sense, thanks again appreciate ur time tim