139 lines
3.6 KiB
PHP
139 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V3\Dashboard;
|
|
|
|
use App\Facades\DataTable\DataTableFacade;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Traits\ApiResponse;
|
|
use App\Models\RahdariPoint;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
|
class RoadMaintenanceStationController extends Controller
|
|
{
|
|
use ApiResponse;
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$user = auth()->user();
|
|
auth()->user()->addActivityComplete(1019);
|
|
|
|
$allowedFilters = ['*'];
|
|
$allowedSortings = ['*'];
|
|
|
|
$province = $request->province ?? null;
|
|
$status = $request->status ?? null;
|
|
$type = $request->type ?? null;
|
|
|
|
$query = RahdariPoint::with('files');
|
|
if ($user->can('show-tollhouse')) {
|
|
$query
|
|
->when($province, function ($query, $province) {
|
|
return $query->where('province_id', $province);
|
|
})
|
|
->when($status, function ($query, $status) {
|
|
return $query->where('status', $status);
|
|
})
|
|
->when($type, function ($query, $type) {
|
|
return $query->where('type', $type);
|
|
});
|
|
|
|
} elseif ($user->can('show-tollhouse-province')) {
|
|
$query
|
|
->where('province_id', $user->province_id)
|
|
->when($status, function ($query, $status) {
|
|
return $query->where('status', $status);
|
|
})
|
|
->when($type, function ($query, $type) {
|
|
return $query->where('type', $type);
|
|
});
|
|
|
|
} else {
|
|
return response()->json(['message' => 'Forbidden'], 403);
|
|
}
|
|
$data = DataTableFacade::run(
|
|
$query,
|
|
$request,
|
|
allowedFilters: $allowedFilters,
|
|
allowedSortings: $allowedSortings
|
|
);
|
|
|
|
|
|
$processedData = [];
|
|
|
|
foreach ($data['data'] as $key => $item) {
|
|
$processedData[$key] = $item;
|
|
|
|
|
|
if ($user->can('edit-tollhouse')) {
|
|
$processedData[$key]['canEdit'] = 1;
|
|
} elseif ($user->can('edit-tollhouse-province')) {
|
|
$processedData[$key]['canEdit'] = $item['province_id'] == $user->province_id ? 1 : 0;
|
|
} else {
|
|
$processedData[$key]['canEdit'] = 0;
|
|
}
|
|
|
|
|
|
if ($user->can('delete-tollhouse')) {
|
|
$processedData[$key]['canDelete'] = 1;
|
|
} elseif ($user->can('delete-tollhouse-province')) {
|
|
$processedData[$key]['canDelete'] = $item['province_id'] == $user->province_id ? 1 : 0;
|
|
} else {
|
|
$processedData[$key]['canDelete'] = 0;
|
|
}
|
|
}
|
|
|
|
$data['data'] = $processedData;
|
|
|
|
return response()->json($data);
|
|
}
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
//
|
|
}
|
|
}
|