|
- <?php
-
- namespace App\Http\Controllers\Locations;
-
- use App\Models\Location;
- use Framework\Routing\Router;
-
- class CreateLocationController
- {
- public function handle(Router $router)
- {
- if (!session()->has('user_id')) {
- return redirect($router->route('show-register-form'));
- }
-
- secure();
-
- $data = validate($_POST, [
- 'code' => ['required'],
- 'name' => ['required'],
- 'description' => [],
- 'capacity' => ['positive_integer'],
- ], 'create_location_errors');
-
- $location = new Location();
- $location->code = $data['code'];
- $location->name = $data['name'];
- $location->description = $data['description'] ?? '';
- $location->capacity = !empty($data['capacity']) ? (int) $data['capacity'] : null;
- $location->save();
-
- return redirect($router->route('view-location', ['location' => $location->id]));
- }
- }
|