F
Filament11mo ago
ericmp

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:
class UserSongPlayHistory extends Pivot
class UserSongPlayHistory extends Pivot
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:
class UserSongPlayHistory extends Model
class UserSongPlayHistory extends Model
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
ericmp
ericmpOP11mo ago
anyone ? (:
Tim van Heugten
Tim van Heugten11mo ago
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.
ericmp
ericmpOP11mo ago
👋 hii the pivot has this structure
No description
Tim van Heugten
Tim van Heugten11mo ago
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.
Tim van Heugten
Tim van Heugten11mo ago
This makes sure an id is returned when creating a record, which can then be passed to the edit route.
ericmp
ericmpOP11mo ago
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:
public $incrementing = true;
public $incrementing = true;
thanks a lot should i add it to all my pivots? 🤔
Tim van Heugten
Tim van Heugten11mo ago
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.
ericmp
ericmpOP11mo ago
oh i understand, yeah makes sense, thanks again appreciate ur time tim
Want results from more Discord servers?
Add your server