39 lines
766 B
PHP
39 lines
766 B
PHP
<?php
|
|
|
|
namespace Modules\ManagementTools\Entities;
|
|
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class MtTool extends Model
|
|
{
|
|
protected $table = 'mt_tools';
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $casts = [
|
|
'attributes' => 'array',
|
|
];
|
|
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(self::class, 'parent_id');
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id');
|
|
}
|
|
|
|
public function users()
|
|
{
|
|
return $this->belongsToMany(User::class, 'mt_user_tool', 'tool_id', 'user_id')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function scopeForBusiness($query, $business_id)
|
|
{
|
|
return $query->where('business_id', $business_id);
|
|
}
|
|
}
|