Anons79 Mini Shell

Directory : /home/aplikasiposinfo/public_html/duriancell.fixmate.id/app/Models/
Upload File :
Current File : /home/aplikasiposinfo/public_html/duriancell.fixmate.id/app/Models/LaporanKasir.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class LaporanKasir extends Model
{
    use HasFactory;
    use SoftDeletes;
    protected $guarded = [];
    public function scopeCari($query, $name)
    {
        return $query->where("pengguna_id", $name);
    }
    public function pengguna(): BelongsTo
    {
        return $this->belongsTo(Pengguna::class, 'pengguna_id', 'id');
    }

    public function tokos()
    {
        return $this->morphToMany(Toko::class, 'tokoable', 'tokoables', 'tokoable_id', 'toko_id')
            ->where('tokoable_type', LaporanKasir::class);
    }

    public function scopeFilterToko($query, $toko_id = null)
    {
        if ($toko_id == null) {
            return $query->whereHas("tokos", function ($q) {
                $q->whereIn('tokos.id',auth()->user()->role->tokos->pluck('id')->toArray());
            });
        } else {
            return $query->whereHas("tokos", function ($q)use ($toko_id) {
                $q->where('tokos.id',$toko_id);
            });
        }
    }
}

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]