1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Models/BaseModel.php

61 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Models;
use App\Filters\QueryFilters;
use App\Utils\Traits\UserSessionAttributes;
use Hashids\Hashids;
use Illuminate\Database\Eloquent\Model;
2019-05-01 04:23:13 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
2019-03-28 10:05:13 +01:00
use Illuminate\Support\Facades\Log;
class BaseModel extends Model
{
use UserSessionAttributes;
2019-05-01 04:23:13 +02:00
use SoftDeletes;
//protected $dateFormat = 'Y-m-d H:i:s.u';
2019-05-07 07:08:10 +02:00
public function __call($method, $params)
{
$entity = strtolower(class_basename($this));
if ($entity) {
$configPath = "modules.relations.$entity.$method";
if (config()->has($configPath)) {
$function = config()->get($configPath);
return call_user_func_array(array($this, $function[0]), $function[1]);
}
}
return parent::__call($method, $params);
}
2019-05-01 04:23:13 +02:00
public function scopeCompany($query, $company_id)
{
$query->where('company_id', $company_id);
2019-05-10 08:08:33 +02:00
2019-05-01 04:23:13 +02:00
return $query;
}
public function scopeScope($query)
{
2019-03-28 10:05:13 +01:00
$query->where($this->getTable() .'.company_id', '=', auth()->user()->company()->id);
return $query;
}
}