Skip to content

Commit 761f8d2

Browse files
Fix issue when using UUID as primary key
1 parent f990eda commit 761f8d2

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

routes/api.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828

2929
// Device token management (authenticated endpoints)
3030
Route::get('device-tokens', 'DeviceTokenController@index');
31-
Route::put('device-tokens/{id}', 'DeviceTokenController@update');
31+
Route::put('device-tokens/{id}', 'DeviceTokenController@update')->wherePrimaryKey();
3232
Route::delete('device-tokens/by-token', 'DeviceTokenController@destroyByToken');
33-
Route::delete('device-tokens/{id}', 'DeviceTokenController@destroy');
34-
Route::post('device-tokens/{id}/deactivate', 'DeviceTokenController@deactivate');
33+
Route::delete('device-tokens/{id}', 'DeviceTokenController@destroy')->wherePrimaryKey();
34+
Route::post('device-tokens/{id}/deactivate', 'DeviceTokenController@deactivate')->wherePrimaryKey();
3535

3636
// Notifications (authenticated endpoints)
3737
Route::get('notifications', 'NotificationController@index');
3838
Route::get('notifications/stats', 'NotificationController@getStats');
3939
Route::post('notifications/mark-all-read', 'NotificationController@markAllAsRead');
40-
Route::post('notifications/{id}/read', 'NotificationController@markAsRead');
41-
Route::post('notifications/{id}/clicked', 'NotificationController@markAsClicked');
42-
Route::delete('notifications/{id}', 'NotificationController@destroy');
40+
Route::post('notifications/{id}/read', 'NotificationController@markAsRead')->wherePrimaryKey();
41+
Route::post('notifications/{id}/clicked', 'NotificationController@markAsClicked')->wherePrimaryKey();
42+
Route::delete('notifications/{id}', 'NotificationController@destroy')->wherePrimaryKey();
4343
});
4444
});

src/Models/DeviceToken.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
namespace Botble\Api\Models;
44

55
use Botble\Base\Models\BaseModel;
6+
use Botble\Base\Models\Concerns\HasUuidsOrIntegerIds;
67
use Carbon\Carbon;
78
use Illuminate\Database\Eloquent\Relations\MorphTo;
89

910
class DeviceToken extends BaseModel
1011
{
12+
use HasUuidsOrIntegerIds;
13+
1114
protected $table = 'device_tokens';
1215

1316
protected $fillable = [
@@ -56,7 +59,7 @@ public function scopeForPlatform($query, string $platform)
5659
return $query->where('platform', $platform);
5760
}
5861

59-
public function scopeForUser($query, string $userType, int $userId)
62+
public function scopeForUser($query, string $userType, int|string $userId)
6063
{
6164
return $query->where('user_type', $userType)->where('user_id', $userId);
6265
}

src/Models/PushNotification.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
namespace Botble\Api\Models;
44

55
use Botble\Base\Models\BaseModel;
6+
use Botble\Base\Models\Concerns\HasUuidsOrIntegerIds;
67
use Illuminate\Database\Eloquent\Relations\BelongsTo;
78
use Illuminate\Database\Eloquent\Relations\HasMany;
89

910
class PushNotification extends BaseModel
1011
{
12+
use HasUuidsOrIntegerIds;
13+
1114
protected $table = 'push_notifications';
1215

1316
protected $fillable = [

src/Models/PushNotificationRecipient.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
namespace Botble\Api\Models;
44

55
use Botble\Base\Models\BaseModel;
6+
use Botble\Base\Models\Concerns\HasUuidsOrIntegerIds;
67
use Illuminate\Database\Eloquent\Relations\BelongsTo;
78
use Illuminate\Database\Eloquent\Relations\MorphTo;
89

910
class PushNotificationRecipient extends BaseModel
1011
{
12+
use HasUuidsOrIntegerIds;
13+
1114
protected $table = 'push_notification_recipients';
1215

1316
protected $fillable = [
@@ -43,7 +46,7 @@ public function user(): MorphTo
4346
return $this->morphTo('user', 'user_type', 'user_id');
4447
}
4548

46-
public function scopeForUser($query, string $userType, int $userId)
49+
public function scopeForUser($query, string $userType, int|string $userId)
4750
{
4851
return $query->where('user_type', $userType)->where('user_id', $userId);
4952
}
@@ -136,9 +139,9 @@ public function isClicked(): bool
136139
}
137140

138141
public static function createForUser(
139-
int $pushNotificationId,
142+
int|string $pushNotificationId,
140143
string $userType,
141-
int $userId,
144+
int|string $userId,
142145
?string $deviceToken = null,
143146
?string $platform = null
144147
): self {

0 commit comments

Comments
 (0)