generated from Flycro/laravel-nuxt
feat: Realtime Functionality
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
42
app/Events/BookRecommendation/BookRecommendationCreated.php
Normal file
42
app/Events/BookRecommendation/BookRecommendationCreated.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\BookRecommendation;
|
||||
|
||||
use App\Models\BookRecommendation;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BookRecommendationCreated implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public BookRecommendation $bookRecommendation
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'BookRecommendationCreated';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('BookRecommendation'),
|
||||
];
|
||||
}
|
||||
}
|
||||
42
app/Events/BookRecommendation/BookRecommendationDeleted.php
Normal file
42
app/Events/BookRecommendation/BookRecommendationDeleted.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\BookRecommendation;
|
||||
|
||||
use App\Models\BookRecommendation;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BookRecommendationDeleted implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public BookRecommendation $bookRecommendation
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'BookRecommendationDeleted';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('BookRecommendation'),
|
||||
];
|
||||
}
|
||||
}
|
||||
42
app/Events/BookRecommendation/BookRecommendationUpdated.php
Normal file
42
app/Events/BookRecommendation/BookRecommendationUpdated.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\BookRecommendation;
|
||||
|
||||
use App\Models\BookRecommendation;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BookRecommendationUpdated implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public BookRecommendation $bookRecommendation
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'BookRecommendationUpdated';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('BookRecommendation'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,12 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\BookRecommendation\BookRecommendationCreated;
|
||||
use App\Events\BookRecommendation\BookRecommendationDeleted;
|
||||
use App\Events\BookRecommendation\BookRecommendationUpdated;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class BookRecommendation extends Model
|
||||
{
|
||||
@@ -20,20 +25,35 @@ class BookRecommendation extends Model
|
||||
'published_at',
|
||||
];
|
||||
|
||||
protected static function booted() :void
|
||||
{
|
||||
static::created(static function ($bookRecommendation) {
|
||||
broadcast(new BookRecommendationCreated($bookRecommendation))->toOthers();
|
||||
});
|
||||
|
||||
static::updated(static function ($task) {
|
||||
broadcast(new BookRecommendationUpdated($task))->toOthers();
|
||||
});
|
||||
|
||||
static::deleting(static function ($task) {
|
||||
broadcast(new BookRecommendationDeleted($task))->toOthers();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that recommended the book.
|
||||
*/
|
||||
public function recommender()
|
||||
public function recommender(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'recommended_by');
|
||||
}
|
||||
|
||||
public function votes()
|
||||
public function votes(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vote::class);
|
||||
}
|
||||
|
||||
public function deadlines()
|
||||
public function deadlines(): HasMany
|
||||
{
|
||||
return $this->hasMany(Deadline::class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user