create show access middleware
This commit is contained in:
@@ -7,10 +7,10 @@ enum MissionStates: int
|
||||
case REQUEST_CREATED= 1;
|
||||
case PENDING_CONFIRMATION = 2;
|
||||
case START_MISSION = 3;
|
||||
|
||||
case END_MISSION = 4;
|
||||
case REJECT_BY_TRANSPORTATION = 5;
|
||||
case REJECT_BY_CONTROL_UNIT = 6;
|
||||
case CANCELLED = 7;
|
||||
|
||||
public static function name(int $state): string
|
||||
{
|
||||
@@ -21,6 +21,7 @@ enum MissionStates: int
|
||||
4 => 'اتمام ماموریت',
|
||||
5 => 'عدم تخصیص خودرو توسط واحد نقلیه و بازگشت درخواست به کارتابل کاربر',
|
||||
6 => 'عدم تایید توسط واحد کنترل',
|
||||
7 => 'ماموریت لغو شد',
|
||||
];
|
||||
|
||||
return $mapArray[$state];
|
||||
|
||||
32
app/Http/Middleware/ValidateShowAccess.php
Normal file
32
app/Http/Middleware/ValidateShowAccess.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Exceptions\ProhibitedAction;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Throwable;
|
||||
|
||||
class ValidateShowAccess
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Closure(Request): (Response) $next
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
throw_if (is_null($user->province_id),
|
||||
new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
throw_if(is_null($user->edarate_shahri_id),
|
||||
new ProhibitedAction('اداره شهری برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -3,24 +3,24 @@
|
||||
namespace App\Services\Cartables\Mission;
|
||||
|
||||
use App\Enums\MissionStates;
|
||||
use App\Exceptions\ProhibitedAction;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\Mission;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class TransportationUnitService
|
||||
{
|
||||
public function dataTable(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = [
|
||||
'id', '', '', '', ''
|
||||
'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name',
|
||||
'description', 'requested_machine_type', 'requested_machine_numbers', 'type',
|
||||
'start_date', 'end_date', 'request_date', 'start_point', 'end_point',
|
||||
];
|
||||
|
||||
// throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$query = Mission::query()->where('state_id', '=', MissionStates::REQUEST_CREATED->value);
|
||||
$query = Mission::query()
|
||||
->where('state_id', '=', MissionStates::REQUEST_CREATED->value)
|
||||
->where('edare_shahri_name', '=', Auth::user()->edarate_shahri_id);
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
|
||||
@@ -14,13 +14,14 @@ return new class extends Migration
|
||||
Schema::create('missions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->string('username');
|
||||
$table->foreignId('machine_id')->nullable()->constrained('cmms_machines')->noActionOnDelete();
|
||||
$table->foreignId('rahdar_id')->constrained('rahdaran')->noActionOnDelete();
|
||||
$table->foreignId('state_id')->constrained('mission_states')->noActionOnDelete();
|
||||
$table->string('state_name');
|
||||
$table->foreignId('province_id')->constrained('provinces')->noActionOnDelete();
|
||||
$table->foreignId('province_id')->nullable()->constrained('provinces')->noActionOnDelete();
|
||||
$table->string('province_name');
|
||||
$table->foreignId('edare_shahri_id')->constrained('edarate_shahri')->noActionOnDelete();
|
||||
$table->foreignId('edare_shahri_id')->nullable()->constrained('edarate_shahri')->noActionOnDelete();
|
||||
$table->string('edare_shahri_name');
|
||||
$table->string('requested_machine_type');
|
||||
$table->integer('requested_machine_numbers');
|
||||
|
||||
Reference in New Issue
Block a user