feat: localize guest endpoints and caching
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\EventTasksCacheService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -17,7 +18,9 @@ class Task extends Model
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'tasks';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'due_date' => 'datetime',
|
||||
'is_completed' => 'bool',
|
||||
@@ -81,6 +84,14 @@ class Task extends Model
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
static::saved(function (Task $task) {
|
||||
app(EventTasksCacheService::class)->forgetForTask($task);
|
||||
});
|
||||
|
||||
static::deleted(function (Task $task) {
|
||||
app(EventTasksCacheService::class)->forgetForTask($task);
|
||||
});
|
||||
}
|
||||
|
||||
protected static function generateSlug(string $base): string
|
||||
@@ -88,7 +99,7 @@ class Task extends Model
|
||||
$slugBase = Str::slug($base) ?: 'task';
|
||||
|
||||
do {
|
||||
$slug = $slugBase . '-' . Str::random(6);
|
||||
$slug = $slugBase.'-'.Str::random(6);
|
||||
} while (static::where('slug', $slug)->exists());
|
||||
|
||||
return $slug;
|
||||
@@ -97,6 +108,6 @@ class Task extends Model
|
||||
public function assignedEvents(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Event::class, 'event_task', 'task_id', 'event_id')
|
||||
->withTimestamps();
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user