diff --git a/app/Enums/RoleEnum.php b/app/Enums/RoleEnum.php new file mode 100644 index 0000000..90b3114 --- /dev/null +++ b/app/Enums/RoleEnum.php @@ -0,0 +1,15 @@ + $this->carRepository->getAllCars(), + ]); + } + + /** + * Show the form for creating a new resource. + */ + public function create(): View + { + return view('cars.create'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(CarPostRequest $request): RedirectResponse + { + $this->carRepository->createCar($request->validated()); + + return redirect()->route('cars.index'); + } + + /** + * Display the specified resource. + */ + public function show(Car $car): View + { + return view('cars.show', [ + 'car' => $car, + ]); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(Car $car): View + { + return view('cars.edit', [ + 'car' => $car, + ]); + } + + /** + * Update the specified resource in storage. + */ + public function update(CarPostRequest $request, Car $car): RedirectResponse + { + $this->carRepository->updateCar($car, $request->validated()); + + return redirect()->route('cars.index'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Car $car): RedirectResponse + { + $this->carRepository->deleteCar($car); + + return redirect()->route('cars.index'); + } +} diff --git a/app/Http/Controllers/DeliveryController.php b/app/Http/Controllers/DeliveryController.php new file mode 100644 index 0000000..703db8d --- /dev/null +++ b/app/Http/Controllers/DeliveryController.php @@ -0,0 +1,86 @@ + $this->deliveryRepository->getAllDeliveries(), + ]); + } + + /** + * Show the form for creating a new resource. + */ + public function create(): View + { + return view('deliveries.create'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(DeliveryPostRequest $request): RedirectResponse + { + $this->deliveryRepository->createDelivery($request->validated()); + + return redirect()->route('deliveries.index'); + } + + /** + * Display the specified resource. + */ + public function show(Delivery $delivery): View + { + return view('deliveries.show', [ + 'delivery' => $delivery, + ]); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(Delivery $delivery): View + { + return view('deliveries.edit', [ + 'delivery' => $delivery, + ]); + } + + /** + * Update the specified resource in storage. + */ + public function update(DeliveryPostRequest $request, Delivery $delivery): RedirectResponse + { + $this->deliveryRepository->updateDelivery($delivery, $request->validated()); + + return redirect()->route('deliveries.index'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Delivery $delivery): RedirectResponse + { + $this->deliveryRepository->deleteDelivery($delivery); + + return redirect()->route('deliveries.index'); + } +} diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 0000000..b917479 --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,85 @@ + $this->userRepository->getAllUsers() + ]); + } + + /** + * Show the form for creating a new resource. + */ + public function create(): View + { + return view('users.create'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(UserPostRequest $request): RedirectResponse + { + $this->userRepository->createUser($request->validated()); + + return redirect()->route('users.index'); + } + + /** + * Display the specified resource. + */ + public function show(User $user): View + { + return view('users.show', [ + 'user' => $user, + ]); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(User $user): View + { + return view('users.edit', [ + 'user' => $user, + ]); + } + + /** + * Update the specified resource in storage. + */ + public function update(UserPostRequest $request, User $user): RedirectResponse + { + $this->userRepository->updateUser($user, $request->validated()); + + return redirect()->route('users.index'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(User $user): RedirectResponse + { + $this->userRepository->deleteUser($user); + + return redirect()->route('users.index'); + } +} diff --git a/app/Http/Controllers/WarehouseController.php b/app/Http/Controllers/WarehouseController.php new file mode 100644 index 0000000..945f247 --- /dev/null +++ b/app/Http/Controllers/WarehouseController.php @@ -0,0 +1,85 @@ + $this->warehouseRepository->getAllWarehouses(), + ]); + } + + /** + * Show the form for creating a new resource. + */ + public function create(): View + { + return view('warehouses.view'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(WarehousePostRequest $request): RedirectResponse + { + $this->warehouseRepository->createWarehouse($request->validated()); + + return redirect()->route('warehouses.index'); + } + + /** + * Display the specified resource. + */ + public function show(Warehouse $warehouse): View + { + return view('warehouses.show', [ + 'warehouse' => $warehouse, + ]); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(Warehouse $warehouse): View + { + return view('warehouse.edit', [ + 'warehouse' => $warehouse, + ]); + } + + /** + * Update the specified resource in storage. + */ + public function update(WarehousePostRequest $request, Warehouse $warehouse): RedirectResponse + { + $this->warehouseRepository->updateWarehouse($warehouse, $request->validated()); + + return redirect()->route('warehouses.index'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Warehouse $warehouse): RedirectResponse + { + $this->warehouseRepository->deleteWarehouse($warehouse); + + return redirect()->route('warehouses.index'); + } +} diff --git a/app/Http/Requests/CarPostRequest.php b/app/Http/Requests/CarPostRequest.php new file mode 100644 index 0000000..9f95e73 --- /dev/null +++ b/app/Http/Requests/CarPostRequest.php @@ -0,0 +1,22 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => 'required|string|max:255', + 'number' => 'required|string|max:255', + 'driver_id' => 'required|exists:users,id', + ]; + } +} diff --git a/app/Http/Requests/DeliveryPostRequest.php b/app/Http/Requests/DeliveryPostRequest.php new file mode 100644 index 0000000..4fd1e39 --- /dev/null +++ b/app/Http/Requests/DeliveryPostRequest.php @@ -0,0 +1,20 @@ +|string> + */ + public function rules(): array + { + return [ + 'delivery' => 'required|string|max:255', + ]; + } +} diff --git a/app/Http/Requests/UserPostRequest.php b/app/Http/Requests/UserPostRequest.php new file mode 100644 index 0000000..d400d83 --- /dev/null +++ b/app/Http/Requests/UserPostRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => 'required|string|max:255', + 'surname' => 'required|string|max:255', + 'patronymic' => 'required|string|max:255', + 'email' => 'required|max:255|email|lowercase', + 'password' => 'required|max:255', + 'role' => ['required', Rule::in(RoleEnum::getRange())], + 'phone_number' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10', + ]; + } +} diff --git a/app/Http/Requests/WarehousePostRequest.php b/app/Http/Requests/WarehousePostRequest.php new file mode 100644 index 0000000..77ad0bc --- /dev/null +++ b/app/Http/Requests/WarehousePostRequest.php @@ -0,0 +1,21 @@ +|string> + */ + public function rules(): array + { + return [ + 'address' => 'required|string|max:255', + 'phone_number' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10', + ]; + } +} diff --git a/app/Models/Car.php b/app/Models/Car.php index 65fff20..71590b0 100644 --- a/app/Models/Car.php +++ b/app/Models/Car.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Car extends Model { @@ -14,4 +15,9 @@ class Car extends Model 'number', 'driver_id', ]; + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } } diff --git a/app/Models/Delivery.php b/app/Models/Delivery.php index b180f77..fa1ae7a 100644 --- a/app/Models/Delivery.php +++ b/app/Models/Delivery.php @@ -4,6 +4,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Delivery extends Model { @@ -15,4 +17,14 @@ class Delivery extends Model 'sending_date', 'delivery_date', ]; + + public function users(): BelongsToMany + { + return $this->belongsToMany(User::class); + } + + public function warehouse(): BelongsTo + { + return $this->belongsTo(Warehouse::class); + } } diff --git a/app/Models/User.php b/app/Models/User.php index b344ad9..ba01a1f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,6 +4,8 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; @@ -46,4 +48,14 @@ class User extends Authenticatable 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; + + public function car(): HasOne + { + return $this->hasOne(Car::class); + } + + public function deliveries(): BelongsToMany + { + return $this->belongsToMany(Delivery::class); + } } diff --git a/app/Models/Warehouse.php b/app/Models/Warehouse.php index 03650b4..3bb3496 100644 --- a/app/Models/Warehouse.php +++ b/app/Models/Warehouse.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; class Warehouse extends Model { @@ -13,4 +14,9 @@ class Warehouse extends Model 'address', 'phoneNumber', ]; + + public function delivery(): HasMany + { + return $this->hasMany(Delivery::class); + } } diff --git a/database/migrations/2024_01_10_065912_create_deliveries_table.php b/database/migrations/2024_01_10_065912_create_deliveries_table.php index 15cd6e6..4505305 100644 --- a/database/migrations/2024_01_10_065912_create_deliveries_table.php +++ b/database/migrations/2024_01_10_065912_create_deliveries_table.php @@ -14,8 +14,9 @@ return new class extends Migration Schema::create('deliveries', function (Blueprint $table) { $table->id(); $table->unsignedInteger('status'); - $table->date('sending_date'); - $table->date('delivery_date'); + $table->date('sending_date')->nullable(); + $table->date('delivery_date')->nullable(); + $table->foreignId('warehouse_id')->constrained('warehouses'); $table->timestamps(); }); } diff --git a/routes/web.php b/routes/web.php index d259f33..fade5b6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ UserController::class, +]);