<?php

namespace App\Models;

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

class WorkHourManage extends Model
{
    use HasFactory;

    protected $fillable = [
       'storeowner_id' ,'day', 'status', 'start_time', 'end_time','store_detail_id'
    ];

    public function storeowner(){
        return $this->belongsTo(User::class, 'storeowner_id', 'id');
    }
    public function store(){
        return $this->belongsTo(Store::class, 'store_detail_id', 'id');
    }

    public function scopeMyWorkinhour($query){
        $user = auth()->user();
        if(in_array($user->user_type, ['admin'])) {
            return $query;
        }
        if($user->user_type == 'storeowner') {
            return $query->where('storeowner_id', $user->id);
        }
    }
}
