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
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @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 Illuminate\Database\Eloquent\Relations\Pivot;
|
|
|
|
|
|
|
|
class CompanyUser extends Pivot
|
2018-11-02 11:54:46 +01:00
|
|
|
{
|
2020-02-26 04:26:07 +01:00
|
|
|
|
|
|
|
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
// protected $guarded = ['id'];
|
2019-11-22 22:10:53 +01:00
|
|
|
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
|
2019-01-15 23:00:25 +01:00
|
|
|
/**
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2019-09-26 00:27:26 +02:00
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
2019-11-29 12:15:50 +01:00
|
|
|
'settings' => 'object',
|
2019-01-15 23:00:25 +01:00
|
|
|
];
|
|
|
|
|
2019-11-21 09:38:57 +01:00
|
|
|
protected $fillable = [
|
|
|
|
'account_id',
|
|
|
|
'permissions',
|
|
|
|
'settings',
|
|
|
|
'is_admin',
|
|
|
|
'is_owner',
|
|
|
|
'is_locked'
|
|
|
|
];
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
public function account()
|
|
|
|
{
|
2019-09-11 02:37:53 +02:00
|
|
|
return $this->belongsTo(Account::class);
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|
|
|
|
|
2019-06-25 05:55:02 +02:00
|
|
|
public function user_pivot()
|
2018-11-02 11:54:46 +01:00
|
|
|
{
|
2019-01-19 11:35:21 +01:00
|
|
|
return $this->hasOne(User::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked');
|
2019-01-07 12:30:28 +01:00
|
|
|
}
|
|
|
|
|
2019-06-25 05:55:02 +02:00
|
|
|
public function company_pivot()
|
2019-01-07 12:30:28 +01:00
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->hasOne(Company::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked');
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|
2019-06-25 05:55:02 +02:00
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
2019-11-24 09:19:53 +01:00
|
|
|
return $this->belongsTo(User::class);
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function company()
|
|
|
|
{
|
2019-11-24 09:19:53 +01:00
|
|
|
return $this->belongsTo(Company::class);
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
|
|
|
|
2019-10-30 08:48:44 +01:00
|
|
|
public function users()
|
|
|
|
{
|
|
|
|
return $this->hasMany(User::class);
|
|
|
|
}
|
|
|
|
|
2019-10-09 07:47:12 +02:00
|
|
|
/*todo monitor this function - may fail under certain conditions*/
|
2019-06-25 05:55:02 +02:00
|
|
|
public function token()
|
|
|
|
{
|
2020-02-26 04:26:07 +01:00
|
|
|
return $this->hasMany(CompanyToken::class, 'user_id', 'user_id');
|
|
|
|
|
|
|
|
//return $this->hasMany(CompanyToken::class);
|
|
|
|
//return $this->hasOne(CompanyToken::class, 'user_id', 'user_id','company_id', 'company_id');
|
|
|
|
|
|
|
|
//return $this->hasOneDeep(CompanyToken::class, [CompanyUser::class], ['user_id','company_id'], ['company_id','company_id']);
|
|
|
|
|
|
|
|
//return $this->belongsTo(CompanyToken::class, 'user_id', 'user_id');
|
|
|
|
|
|
|
|
// return $this->hasOneThrough(
|
|
|
|
// CompanyToken::class,
|
|
|
|
// CompanyUser::class,
|
|
|
|
// 'user_id', // Foreign key on CompanyUser table...
|
|
|
|
// 'company_id', // Foreign key on CompanyToken table...
|
|
|
|
// 'user_id', // Local key on CompanyToken table...
|
|
|
|
// 'company_id' // Local key on CompanyUser table...
|
|
|
|
// );
|
|
|
|
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
2020-02-26 04:26:07 +01:00
|
|
|
|
|
|
|
public function tokens()
|
|
|
|
{
|
|
|
|
return $this->hasMany(CompanyToken::class, 'user_id', 'user_id');
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|