This commit is contained in:
2022-11-01 11:07:41 +08:00
commit c23de98690
131 changed files with 14088 additions and 0 deletions

30
app/Models/Like.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Like extends Model
{
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function likeable(): MorphTo
{
return $this->morphTo();
}
public function liker(): BelongsTo
{
return $this->user();
}
public function scopeWithType(Builder $query, string $type): Builder
{
return $query->where('likeable_type', app($type)->getMorphClass());
}
}