refactore the relation
This commit is contained in:
@@ -50,14 +50,14 @@ class RoadItemsProjectController extends Controller
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-road-item-supervise-cartable')) {
|
||||
$query = RoadItemsProject::query()->where('is_new', 1)->with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id']);
|
||||
$query = RoadItemsProject::query()->where('is_new', 1)->with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code']);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-road-item-supervise-cartable-province')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
$query = RoadItemsProject::query()->where('is_new', 1)
|
||||
->with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id'])->where('province_id', auth()->user()->province_id);
|
||||
->with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code'])->where('province_id', auth()->user()->province_id);
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
@@ -154,7 +154,7 @@ class RoadItemsProjectController extends Controller
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id'])
|
||||
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code'])
|
||||
->where('is_new', 1)
|
||||
->where('user_id', auth()->user()->id);
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ class RoadItemsProject extends Model
|
||||
|
||||
public function cmmsMachine(): HasOne
|
||||
{
|
||||
return $this->hasOne(CMMSMachine::class);
|
||||
return $this->hasOne(CMMSMachine::class, 'id', 'cmms_machine_id');
|
||||
}
|
||||
|
||||
public function rahdaran(): BelongsToMany
|
||||
|
||||
Reference in New Issue
Block a user