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

Commit

Permalink
fix and complete find vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina committed May 15, 2022
1 parent 5175f3e commit dda1784
Show file tree
Hide file tree
Showing 18 changed files with 556 additions and 484 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function store(LoginRequest $request)
return redirect(route('admin_dashboard'));
}

return redirect()->intended(RouteServiceProvider::HOME);
return back()->withInput();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public function store(Request $request)

Auth::login($user);

return redirect(RouteServiceProvider::HOME);
return redirect('update-profile');
}
}
41 changes: 28 additions & 13 deletions app/Http/Controllers/RentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,55 @@ public function getFindCar()
public function findVehicles() {
$request = request()->input();
$type = $request['type'];
$pickup_date = $request['pickup_date'];
$dropoff_date = $request['dropoff_date'];
$transmission = isset($request['transmission']) ? $request['transmission'] : 'All';
$brand = isset($request['brand']) ? $request['brand'] : 'All';

$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'])
$vehicles = Vehicle::leftJoin('orders', 'vehicles.id', '=', 'orders.vehicle_id')
->select("vehicles.id", "vehicles.name", "vehicles.brand", "vehicles.transmission", "vehicles.cc", "vehicles.fuel", "vehicles.price", "vehicles.type", "vehicles.photo", "vehicles.year")
->where("type", "=", $type)
->whereNull("orders.pickup_date")
->when($pickup_date && $dropoff_date, function($query) use ($pickup_date, $dropoff_date) {
$query->orWhere("orders.dropoff_date", "<", $pickup_date)
->orWhere("orders.pickup_date", ">", $dropoff_date);
})
->when($brand != 'All', function($query, $brand) {
$query->where('vehicles.brand', $brand);
})
->when($transmission != 'All', function($query, $transmission) {
$query->where('vehicles.transmission', $transmission);
})
->groupBy("vehicles.id")
->having('vehicles.available_unit', '>', DB::raw('count(orders.id)'))
->get();

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

public function getFindMotor()
{
return view('find-vehicles', ['type' => 'Motor']);
}

public function getRentCarForm()
public function getRentForm($id)
{
return view('rent-form');
}
$vehicle = Vehicle::find($id);

public function getRentMotorForm()
{
return view('rent-form');
return view('rent-form', ['vehicle' => $vehicle]);
}

public function getRentCars()
{
return view('vehicles-list', ['vehicles' => session('vehicles'), 'type' => 'car']);
if(!session('vehicles')) return redirect()->route(('find-car'));

return view('vehicles-list', ['vehicles' => session('vehicles'), 'pickup_date' => session('pickup_date'), 'dropoff_date' => session('dropoff_date'), 'type' => 'Car']);
}

public function getRentMotors()
{
return view('vehicles-list', ['vehicles' => session('vehicles'), 'type' => 'motor']);
if(session('vehicles') == null) return redirect()->route(('find-motor'));

return view('vehicles-list', ['vehicles' => session('vehicles'), 'pickup_date' => session('pickup_date'), 'dropoff_date' => session('dropoff_date'), 'type' => 'Motor']);
}
}
2 changes: 1 addition & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
*/

'links' => [
public_path('storage') => storage_path('app/public'),
public_path('storage') => storage_path('app/public')
],

];
32 changes: 0 additions & 32 deletions database/migrations/2022_05_10_091301_create_brands_table.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
Schema::create('vehicles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('brand_id')->references('id')->on('brands');
$table->string('brand');
$table->string('transmission');
$table->string('fuel');
$table->integer('cc')->unsigned();
Expand Down
28 changes: 0 additions & 28 deletions database/seeders/BrandSeeder.php

This file was deleted.

64 changes: 64 additions & 0 deletions database/seeders/VehicleSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class VehicleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$data = [
[
'name' => 'Honda Scoopy Smart Key',
'brand' => 'Honda',
'transmission' => 'Automatic',
'fuel' => 'Pertamax',
'cc' => 110,
'price' => 105000,
'type' => 'motor',
'photo' => 'Honda Scoopy Smart Key.jpg',
'created_at' => date("Y-m-d H:i:s"),
'updated_at' => date("Y-m-d H:i:s"),
'year' => 2022,
'available_unit' => 3
],
[
'name' => 'Honda Revo X',
'brand' => 'Honda',
'transmission' => 'Manual',
'fuel' => 'Pertamax',
'cc' => 110,
'price' => 90000,
'type' => 'motor',
'photo' => 'Honda Revo X.jpg',
'created_at' => date("Y-m-d H:i:s"),
'updated_at' => date("Y-m-d H:i:s"),
'year' => 2019,
'available_unit' => 2
],
[
'name' => 'Honda BeAT FI',
'brand' => 'Honda',
'transmission' => 'Automatic',
'fuel' => 'Pertamax',
'cc' => 110,
'price' => 85000,
'type' => 'motor',
'photo' => 'Honda BeAT FI.jpg',
'created_at' => date("Y-m-d H:i:s"),
'updated_at' => date("Y-m-d H:i:s"),
'year' => 2019,
'available_unit' => 3
]
];

\DB::table('vehicles')->insert($data);
}
}
Loading

0 comments on commit dda1784

Please sign in to comment.