Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
add logic to find vehicles form
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina committed May 13, 2022
1 parent d3700bd commit 39707e9
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 15 deletions.
25 changes: 23 additions & 2 deletions app/Http/Controllers/RentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,32 @@

use Illuminate\Http\Request;

use Illuminate\Support\Facades\DB;

use App\Models\Vehicle;

use App\Models\Order;

class RentController extends Controller
{
public function getFindCar()
{
return view('find-vehicles');
return view('find-vehicles', ['type' => 'Car']);
}

public function findVehicles() {
$request = request()->input();
$type = $request['type'];

$vehicles = Vehicle::join('orders', 'vehicles.id', '=', 'orders.vehicle_id')
->select("vehicles.id", "vehicles.name", "vehicles.brand_id", "vehicles.transmission", "vehicles.cc", "vehicles.price", "vehicles.type", "vehicles.photo", "vehicles.year")
->where("orders.dropoff_date", "<", $request['pickup_date'])
->orWhere("orders.pickup_date", ">", $request['dropoff_date'])
->groupBy("vehicles.id")
->having('vehicles.available_unit', '>', DB::raw('count(orders.id)'))
->get();

return redirect()->route('rent-'. strtolower($type). 's', ['vehicles' => $vehicles]);
}

public function getFindMotor()
Expand All @@ -28,7 +49,7 @@ public function getRentMotorForm()

public function getRentCars()
{
return view('vehicles-list');
return view('vehicles-list', ['vehicles' => session('vehicles'), 'type' => 'Car']);
}

public function getRentMotors()
Expand Down
8 changes: 4 additions & 4 deletions database/migrations/2022_05_13_062551_update_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('phone_1');
$table->string('phone_2');
$table->string('address_id');
$table->string('address_mlg');
$table->string('phone_1')->nullable();
$table->string('phone_2')->nullable();
$table->string('address_id')->nullable();
$table->string('address_mlg')->nullable();
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('vehicles', function (Blueprint $table) {
$table->integer('available_unit')->nullable()->unsigned();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('vehicles', function (Blueprint $table) {
$table->dropColumn('available_unit');
});
}
};
44 changes: 44 additions & 0 deletions database/seeders/UserSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$data = [
[
'name' => 'John Doe' ,
'email' => '[email protected]',
'password' => Hash::make('password'),
'role' => 'admin',
'email_verified_at' => now()
],
[
'name' => 'Jane Doe' ,
'email' => '[email protected]',
'password' => Hash::make('password'),
'role' => 'admin',
'email_verified_at' => now()
],
[
'name' => 'John Smith' ,
'email' => '[email protected]',
'password' => Hash::make('password'),
'role' => 'admin',
'email_verified_at' => now()
]
];

\DB::table('users')->insert($data);
}
}
14 changes: 8 additions & 6 deletions resources/views/find-vehicles.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
<x-base-body selected="true">
<div class="min-h-screen flex flex-col sm:justify-center items-center sm:pt-0 bg-">
<div class="w-3/6 max-w-4xl mt-6 px-12 py-20 bg-white shadow-md overflow-hidden sm:rounded-lg">
<h3 class="font-bold text-center text-3xl text-lilac-100 mt-2">Search for Motorcycle Rent</h3>
<form action="" method="post" class="px-20 mt-8">
<h3 class="font-bold text-center text-3xl text-lilac-100 mt-2">Search for {{ $type }} Rent</h3>
<form action=" {{ '/find/'.$type }}" method="post" class="px-20 mt-8">
@csrf
<x-label for="pickup" value="Pick up" class="block font-bold text-base mt-6"/>
<div class="date-time flex">
<x-input id="pickup-date" class="block basis-8/12" type="date" name="pickup-time" value="{{ date('Y-m-d') }}" required />
<x-input id="pickup-time" class="block basis-4/12 ml-4" type="time" name="pickup-date" value="{{ explode(' ', gmdate('Y-m-d h:i \G\M\T'))[1] }}" required />
<x-input id="pickup-date" class="block basis-8/12" type="date" name="pickup_date" value="{{ date('Y-m-d') }}" required />
<x-input id="pickup-time" class="block basis-4/12 ml-4" type="time" name="pickup_time" value="{{ explode(' ', gmdate('Y-m-d h:i \G\M\T'))[1] }}" required />
</div>
<x-label for="dropoff" value="Drop off" class="block font-bold text-base mt-6"/>
<div class="date-time flex">
<x-input id="dropoff-date" class="block basis-8/12" type="date" name="dropoff-time" value="{{ date('Y-m-d', strtotime('tomorrow')) }}" required />
<x-input id="dropoff-time" class="block basis-4/12 ml-4" type="time" name="dropoff-date" value="{{ explode(' ', gmdate('Y-m-d h:i \G\M\T'))[1] }}" required />
<x-input id="dropoff-date" class="block basis-8/12" type="date" name="dropoff_date" value="{{ date('Y-m-d', strtotime('tomorrow')) }}" required />
<x-input id="dropoff-time" class="block basis-4/12 ml-4" type="time" name="dropoff_time" value="{{ explode(' ', gmdate('Y-m-d h:i \G\M\T'))[1] }}" required />
</div>
<input type="hidden" name="type" value="{{ strtolower($type) }}">
<div class="mt-6 flex justify-center">
<x-button filled="true">Rent Now</x-button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions resources/views/layouts/guest.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">

<link rel="icon" href="images/logo.ico" type="image/icon type">

<title>{{ config('app.name', 'Laravel') }}</title>

<!-- Fonts -->
Expand Down
Empty file.
10 changes: 7 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@

Route::get('/me/profile', [UserController::class, 'getUserProfile']);

Route::get('/find/motor', [RentController::class, 'getFindVehicles']);
Route::get('/find/motor', [RentController::class, 'getFindMotor']);

Route::get('/find/car', [RentController::class, 'getFindCar']);

Route::get('/rent/motors', [RentController::class, 'getRentMotors']);
Route::post('/find/{type}', [RentController::class, 'findVehicles']);

Route::get('/rent/cars', [RentController::class, 'getRentCars']);
Route::post('/find/motor', [RentController::class, 'findMotor']);

Route::get('/rent/motors', [RentController::class, 'getRentMotors'])->name('rent-motors');

Route::get('/rent/cars', [RentController::class, 'getRentCars'])->name('rent-cars');

Route::middleware(['auth', 'verified'])-> group(function () {
Route::get('/rent/car/{id}', [RentController::class, 'getRentCarForm']);
Expand Down

0 comments on commit 39707e9

Please sign in to comment.