You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have this model in Laravel as an APIResource and I want to set the game_id and user_id properties types to int. I've tried many ways but I haven't figured out the working one yet. Can you help me?
Thanks
<?phpnamespaceApp\Models;
useApiPlatform\Laravel\Eloquent\Filter\EqualsFilter;
useApiPlatform\Metadata\ApiProperty;
useApiPlatform\Metadata\ApiResource;
useApiPlatform\Metadata\QueryParameter;
useApp\Enums\LibraryEntryCompletionStatus;
useApp\Enums\LibraryEntryStatus;
useIlluminate\Database\Eloquent\Model;
useIlluminate\Database\Eloquent\Relations\BelongsTo;
#[ApiResource(
shortName: 'LibraryEntry',
description: "A user's entry in their game library, representing their interaction with a specific game."
)]
#[ApiProperty(description: 'The unique identifier of the game associated with this library entry.', property: 'game_id')]
#[ApiProperty(description: 'The unique identifier of the user who owns this library entry.', types: 'integer', property: 'user_id')]
#[QueryParameter('current_user', filter: EqualsFilter::class, description: 'Filter library entries by the current authenticated user')]
#[QueryParameter('user_id', filter: EqualsFilter::class, description: 'Filter library entries by the associated user ID')]
#[QueryParameter('game_id', filter: EqualsFilter::class, description: 'Filter library entries by the associated game ID')]
class LibraryEntry extends Model
{
protected$fillable = [
'user_id',
'game_id',
'status',
'completion_status',
'owned',
'edition_id',
'platforms_ids',
'start_date',
'end_date',
'played_time',
'rating',
'rating_details',
'review',
];
protectedfunctioncasts(): array
{
return [
'owned' => 'boolean',
'platforms_ids' => 'array',
'start_date' => 'date',
'end_date' => 'date',
'played_time' => 'timestamp',
'rating' => 'float',
'rating_details' => 'array',
'status' => LibraryEntryStatus::class,
'completion_status' => LibraryEntryCompletionStatus::class,
'game_id' => 'int',
'user_id' => 'integer'
];
}
publicfunctionuser(): BelongsTo
{
return$this->belongsTo(User::class);
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have this model in Laravel as an APIResource and I want to set the
game_idanduser_idproperties types toint. I've tried many ways but I haven't figured out the working one yet. Can you help me?Thanks
Beta Was this translation helpful? Give feedback.
All reactions