Skip to content

Commit

Permalink
publish custom token and notification models
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Vostrak authored and Gregor Vostrak committed Jan 21, 2024
1 parent 13282d6 commit d2eb7cf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/Models/Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Notifications\DatabaseNotification;

class Notification extends DatabaseNotification
{
}
11 changes: 11 additions & 0 deletions app/Models/Token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Laravel\Passport\Token as PassportToken;

class Token extends PassportToken
{
}
10 changes: 10 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
Expand Down Expand Up @@ -93,4 +95,12 @@ public function organizations(): BelongsToMany
->withTimestamps()
->as('membership');
}

/**
* @return MorphMany<Notification>
*/
public function notifications(): MorphMany
{
return $this->morphMany(Notification::class, 'notifiable')->latest();
}
}
3 changes: 3 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Providers;

use App\Models\Organization;
use App\Models\Token;
use App\Policies\OrganizationPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Laravel\Jetstream\Jetstream;
Expand Down Expand Up @@ -47,5 +48,7 @@ public function boot(): void

// use passport scopes for jetstream token permissions
Jetstream::permissions(Passport::scopeIds());

Passport::useTokenModel(Token::class);
}
}
23 changes: 23 additions & 0 deletions resources/js/types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export interface Membership {
updated_at: string | null;
}

export interface Notification {
// relations
notifiable: Notification;
}

export interface Organization {
// columns
id: string;
Expand Down Expand Up @@ -106,6 +111,22 @@ export interface TimeEntry {
task: Task;
}

export interface Token {
// columns
id: string;
user_id: string | null;
client_id: string;
name: string | null;
scopes: string[] | null;
revoked: boolean;
created_at: string | null;
updated_at: string | null;
expires_at: string | null;
// relations
client: Client;
user: User;
}

export interface User {
// columns
id: string;
Expand All @@ -125,7 +146,9 @@ export interface User {
profile_photo_url: string;
// relations
organizations: Organization[];
notifications: Notification[];
clients: Client[];
tokens: Token[];
current_team: Organization;
owned_teams: Organization[];
teams: Organization[];
Expand Down

0 comments on commit d2eb7cf

Please sign in to comment.