2018-11-02 11:54:46 +01:00
|
|
|
<?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
|
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-01-19 11:35:21 +01:00
|
|
|
use App\Filters\QueryFilters;
|
2019-02-17 11:34:46 +01:00
|
|
|
use App\Utils\Traits\UserSessionAttributes;
|
2018-11-02 11:54:46 +01:00
|
|
|
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;
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
class BaseModel extends Model
|
|
|
|
{
|
2019-02-17 11:34:46 +01:00
|
|
|
use UserSessionAttributes;
|
2019-05-01 04:23:13 +02:00
|
|
|
use SoftDeletes;
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2019-05-07 12:48:43 +02:00
|
|
|
//protected $dateFormat = 'Y-m-d H:i:s.u';
|
2019-05-07 07:08:10 +02:00
|
|
|
|
2018-12-13 12:01:33 +01:00
|
|
|
public function __call($method, $params)
|
2018-11-02 11:54:46 +01:00
|
|
|
{
|
2018-12-13 12:01:33 +01:00
|
|
|
$entity = strtolower(class_basename($this));
|
2018-11-02 11:54:46 +01:00
|
|
|
|
2018-12-13 12:01:33 +01:00
|
|
|
if ($entity) {
|
|
|
|
$configPath = "modules.relations.$entity.$method";
|
|
|
|
|
|
|
|
if (config()->has($configPath)) {
|
|
|
|
$function = config()->get($configPath);
|
|
|
|
|
2018-12-15 14:04:46 +01:00
|
|
|
return call_user_func_array(array($this, $function[0]), $function[1]);
|
2018-12-13 12:01:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::__call($method, $params);
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|
2019-01-19 11:35:21 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
public function scopeScope($query)
|
|
|
|
{
|
2019-03-28 10:05:13 +01:00
|
|
|
|
|
|
|
$query->where($this->getTable() .'.company_id', '=', auth()->user()->company()->id);
|
2019-02-17 11:34:46 +01:00
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|