<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ShareLog extends BaseModel
{
    use HasFactory;

    public $fillable = ['user_id', 'from_user_id', 'from_type', 'from_source'];

    public function fromUser()
    {
        return $this->belongsTo(User::class, 'from_user_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function scopeOwner($query, $user_id)
    {
        return $query->where('user_id', $user_id);
    }

    public function scopeFromOwner($query, $user_id)
    {
        return $query->where('from_user_id', $user_id);
    }
}
