mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 04:01:10 -04:00
* Create PHP CS Fixer config and add to CI workflow * Run php cs fixer on project * Add newline at end of file * Update to use PHP CS Fixer v3 * Run v3 config on project * Run seperate config in CI
56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Crater\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Unit extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = ['name', 'company_id'];
|
|
|
|
public function items()
|
|
{
|
|
return $this->hasMany(Item::class);
|
|
}
|
|
|
|
public function company()
|
|
{
|
|
return $this->belongsTo(Company::class);
|
|
}
|
|
|
|
public function scopeWhereCompany($query, $company_id)
|
|
{
|
|
$query->where('company_id', $company_id);
|
|
}
|
|
|
|
public function scopeWhereUnit($query, $unit_id)
|
|
{
|
|
$query->orWhere('id', $unit_id);
|
|
}
|
|
|
|
public function scopeApplyFilters($query, array $filters)
|
|
{
|
|
$filters = collect($filters);
|
|
|
|
if ($filters->get('unit_id')) {
|
|
$query->whereUnit($filters->get('unit_id'));
|
|
}
|
|
|
|
if ($filters->get('company_id')) {
|
|
$query->whereCompany($filters->get('company_id'));
|
|
}
|
|
}
|
|
|
|
public function scopePaginateData($query, $limit)
|
|
{
|
|
if ($limit == 'all') {
|
|
return collect(['data' => $query->get()]);
|
|
}
|
|
|
|
return $query->paginate($limit);
|
|
}
|
|
}
|