更新代码
This commit is contained in:
32
app/Models/Favorite.php
Normal file
32
app/Models/Favorite.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\User;
|
||||
use Auth;
|
||||
|
||||
class Favorite extends Model
|
||||
{
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(user::class)->withDefault();
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function scopeMine($query)
|
||||
{
|
||||
return $query->where('user_id', Auth::id());
|
||||
}
|
||||
|
||||
public static function isFavorite($item_id, $type)
|
||||
{
|
||||
$user_id = Auth::id();
|
||||
$item_type = "App\Models\\" . $type;
|
||||
$num = Self::where('user_id', $user_id)->where('item_id', $item_id)->where('item_type', $item_type)->count() ?? 0;
|
||||
return $num;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user