add nested array validation to form requests

This commit is contained in:
2024-11-09 11:36:16 +03:30
parent fbb4db5e60
commit 117bf0269e
5 changed files with 33 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\V3\Azmayesh;
use App\Facades\DataTable\DataTableFacade;
use App\Http\Controllers\Controller;
use App\Http\Requests\V3\AzmayeshType\StoreRequest;
use App\Http\Requests\V3\AzmayeshType\UpdateRequest;
@@ -16,7 +17,27 @@ class AzmayeshTypeController extends Controller
{
use ApiResponse;
public function index(): JsonResponse
public function index(Request $request): JsonResponse
{
$columns = array(
'id', 'name'
);
$allowedFilters = $columns;
$allowedSortings = $columns;
$query = AzmayeshType::query();
$data = DataTableFacade::run(
$query,
$request,
allowedFilters: $allowedFilters,
allowedSortings: $allowedSortings);
return response()->json($data);
}
public function list(): JsonResponse
{
$allTypes = AzmayeshType::all();

View File

@@ -24,6 +24,10 @@ class StoreRequest extends FormRequest
return [
'name' => 'required|string',
'fields' => 'required|array',
'fields.*.name' => 'required|string',
'fields.*.unit' => 'string',
'fields.*.type' => 'required|string',
'fields.*.option' => 'string',
];
}
}

View File

@@ -24,6 +24,10 @@ class UpdateRequest extends FormRequest
return [
'name' => 'required|string',
'fields' => 'required|array',
'fields.*.name' => 'required|string',
'fields.*.unit' => 'string',
'fields.*.type' => 'required|string',
'fields.*.option' => 'string',
];
}
}

View File

@@ -13,8 +13,8 @@ return new class extends Migration
{
Schema::create('azmayesh_field_azmayesh_type', function (Blueprint $table) {
$table->id();
$table->foreignId('azmayesh_field_id')->constrained('azmayesh_fields');
$table->foreignId('azmayesh_type_id')->constrained('azmayesh_types');
$table->foreignId('azmayesh_field_id')->constrained('azmayesh_fields')->cascadeOnDelete();
$table->foreignId('azmayesh_type_id')->constrained('azmayesh_types')->cascadeOnDelete();
$table->timestamps();
});
}

View File

@@ -41,6 +41,7 @@ Route::prefix('azmayesh_types')
->controller(AzmayeshTypeController::class)
->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/list', 'list')->name('list');
Route::get('/fields/{azmayeshType}', 'fields')->name('fields');
Route::get('/{azmayeshType}', 'show')->name('show');
Route::post('/store', 'store')->name('store');