50 lines
1.9 KiB
PHP
50 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cartables;
|
|
|
|
use App\Facades\DataTable\DataTableFacade;
|
|
use App\Http\Traits\ApiResponse;
|
|
use App\Models\SafetyAndPrivacy;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SafetyAndPrivacyTableService
|
|
{
|
|
use ApiResponse;
|
|
|
|
public function dataTable(Request $request, $loadRelations = false)
|
|
{
|
|
$user = auth()->user();
|
|
|
|
$fields = ['id','lat','lon','province_id','province_fa','city_id','city_fa','edare_shahri_id','edare_shahri_name',
|
|
'recognize_picture','action_picture','operator_id','operator_name','way_id','created_at','updated_at','step','judiciary_document',
|
|
'judiciary_document_upload_date','info_id','info_fa','activity_date_time','judiciary_document_upload_date','action_picture_document_upload_date',
|
|
'step_fa'
|
|
];
|
|
|
|
if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable')) {
|
|
$query = SafetyAndPrivacy::query()->select($fields);
|
|
}
|
|
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) {
|
|
if (is_null($user->province_id)) {
|
|
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
|
}
|
|
|
|
$query = SafetyAndPrivacy::query()->where('province_id', '=', $user->province_id)->select($fields);
|
|
}
|
|
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) {
|
|
if (is_null($user->edarate_shahri_id)) {
|
|
return $this->errorResponse('اداره ای برای شما در سامانه ثبت نشده است!');
|
|
}
|
|
|
|
$query = SafetyAndPrivacy::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id);
|
|
}
|
|
|
|
return DataTableFacade::run(
|
|
$query,
|
|
$request,
|
|
allowedFilters: ['*'],
|
|
allowedSortings: ['*']
|
|
);
|
|
}
|
|
}
|