add nested array validation to form requests
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\V3\Azmayesh;
|
namespace App\Http\Controllers\V3\Azmayesh;
|
||||||
|
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\V3\AzmayeshType\StoreRequest;
|
use App\Http\Requests\V3\AzmayeshType\StoreRequest;
|
||||||
use App\Http\Requests\V3\AzmayeshType\UpdateRequest;
|
use App\Http\Requests\V3\AzmayeshType\UpdateRequest;
|
||||||
@@ -16,7 +17,27 @@ class AzmayeshTypeController extends Controller
|
|||||||
{
|
{
|
||||||
use ApiResponse;
|
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();
|
$allTypes = AzmayeshType::all();
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ class StoreRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'fields' => 'required|array',
|
'fields' => 'required|array',
|
||||||
|
'fields.*.name' => 'required|string',
|
||||||
|
'fields.*.unit' => 'string',
|
||||||
|
'fields.*.type' => 'required|string',
|
||||||
|
'fields.*.option' => 'string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ class UpdateRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'fields' => 'required|array',
|
'fields' => 'required|array',
|
||||||
|
'fields.*.name' => 'required|string',
|
||||||
|
'fields.*.unit' => 'string',
|
||||||
|
'fields.*.type' => 'required|string',
|
||||||
|
'fields.*.option' => 'string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('azmayesh_field_azmayesh_type', function (Blueprint $table) {
|
Schema::create('azmayesh_field_azmayesh_type', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('azmayesh_field_id')->constrained('azmayesh_fields');
|
$table->foreignId('azmayesh_field_id')->constrained('azmayesh_fields')->cascadeOnDelete();
|
||||||
$table->foreignId('azmayesh_type_id')->constrained('azmayesh_types');
|
$table->foreignId('azmayesh_type_id')->constrained('azmayesh_types')->cascadeOnDelete();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ Route::prefix('azmayesh_types')
|
|||||||
->controller(AzmayeshTypeController::class)
|
->controller(AzmayeshTypeController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/', 'index')->name('index');
|
Route::get('/', 'index')->name('index');
|
||||||
|
Route::get('/list', 'list')->name('list');
|
||||||
Route::get('/fields/{azmayeshType}', 'fields')->name('fields');
|
Route::get('/fields/{azmayeshType}', 'fields')->name('fields');
|
||||||
Route::get('/{azmayeshType}', 'show')->name('show');
|
Route::get('/{azmayeshType}', 'show')->name('show');
|
||||||
Route::post('/store', 'store')->name('store');
|
Route::post('/store', 'store')->name('store');
|
||||||
|
|||||||
Reference in New Issue
Block a user