Started a flight view
This commit is contained in:
@@ -8,7 +8,9 @@ use Illuminate\Auth\Events\Registered;
|
|||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rules;
|
use Illuminate\Validation\Rules;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
@@ -31,12 +33,21 @@ class RegisteredUserController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function store(Request $request): RedirectResponse
|
public function store(Request $request): RedirectResponse
|
||||||
{
|
{
|
||||||
$request->validate([
|
|
||||||
'name' => 'required|string|max:255',
|
$validator = Validator::make($request->all(), [
|
||||||
|
'name' => 'required|string|max:32|alpha_dash',
|
||||||
'email' => 'required|string|lowercase|email|max:255|unique:'.User::class,
|
'email' => 'required|string|lowercase|email|max:255|unique:'.User::class,
|
||||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$validator->after(function ($validator) use ($request) {
|
||||||
|
if (User::whereRaw(DB::raw('LOWER(name) = ?'), [strtolower($request->name)])->exists()) {
|
||||||
|
$validator->errors()->add('name', 'The name has already been taken.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$validator->validate();
|
||||||
|
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'name' => $request->name,
|
'name' => $request->name,
|
||||||
'email' => $request->email,
|
'email' => $request->email,
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\UserFlight;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
|
||||||
|
class FlightProfileController extends Controller
|
||||||
|
{
|
||||||
|
public function view(string $username)
|
||||||
|
{
|
||||||
|
$user = User::whereRaw(DB::raw('LOWER(name) = ?'), [strtolower($username)])->firstOrFail();
|
||||||
|
|
||||||
|
$flights = UserFlight::where('user_id', $user->id)->get();
|
||||||
|
|
||||||
|
return Inertia::render('FlightProfile', [
|
||||||
|
'user' => $user,
|
||||||
|
'flights' => $flights,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,8 +28,8 @@ const submit = () => {
|
|||||||
<v-col cols="12">
|
<v-col cols="12">
|
||||||
<v-text-field
|
<v-text-field
|
||||||
v-model="form.name"
|
v-model="form.name"
|
||||||
label="Name"
|
label="Username"
|
||||||
autocomplete="name"
|
autocomplete="username"
|
||||||
autofocus
|
autofocus
|
||||||
:error-messages="form.errors.name"
|
:error-messages="form.errors.name"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import MainLayout from "@/Layouts/MainLayout.vue";
|
||||||
|
import { Head } from '@inertiajs/vue3';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
layout: MainLayout
|
||||||
|
})
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
user: {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
email: string
|
||||||
|
}
|
||||||
|
flights: {
|
||||||
|
id: number
|
||||||
|
departure: string
|
||||||
|
arrival: string
|
||||||
|
flight_number: string
|
||||||
|
date: string
|
||||||
|
}[]
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Head :title="`${user.name}'s Flights`" />
|
||||||
|
|
||||||
|
<div class="p-6">
|
||||||
|
<h1 class="text-2xl font-bold mb-6">{{ user.name }}'s Flights</h1>
|
||||||
|
|
||||||
|
<table class="w-full border-collapse border border-gray-300">
|
||||||
|
<thead>
|
||||||
|
<tr class="bg-gray-100">
|
||||||
|
<th class="border border-gray-300 px-4 py-2 text-left">Flight</th>
|
||||||
|
<th class="border border-gray-300 px-4 py-2 text-left">Departure</th>
|
||||||
|
<th class="border border-gray-300 px-4 py-2 text-left">Arrival</th>
|
||||||
|
<th class="border border-gray-300 px-4 py-2 text-left">Date</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="flight in flights" :key="flight.id" class="hover:bg-gray-50">
|
||||||
|
<td class="border border-gray-300 px-4 py-2">{{ flight.flight_number }}</td>
|
||||||
|
<td class="border border-gray-300 px-4 py-2">{{ flight.departure }}</td>
|
||||||
|
<td class="border border-gray-300 px-4 py-2">{{ flight.arrival }}</td>
|
||||||
|
<td class="border border-gray-300 px-4 py-2">{{ flight.date }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="flights.length === 0">
|
||||||
|
<td colspan="4" class="border border-gray-300 px-4 py-2 text-center text-gray-500">
|
||||||
|
No flights found.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
</style>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\FlightImportController;
|
use App\Http\Controllers\FlightImportController;
|
||||||
|
use App\Http\Controllers\FlightProfileController;
|
||||||
use App\Http\Controllers\LogoController;
|
use App\Http\Controllers\LogoController;
|
||||||
use App\Http\Controllers\ProfileController;
|
use App\Http\Controllers\ProfileController;
|
||||||
use App\Http\Controllers\SearchController;
|
use App\Http\Controllers\SearchController;
|
||||||
@@ -19,6 +20,7 @@ Route::domain(config('app.domain'))->group(
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Route::get('/dashboard', function () {
|
Route::get('/dashboard', function () {
|
||||||
return Inertia::render('Dashboard');
|
return Inertia::render('Dashboard');
|
||||||
})->middleware(['auth', 'verified'])->name('dashboard');
|
})->middleware(['auth', 'verified'])->name('dashboard');
|
||||||
@@ -59,6 +61,9 @@ Route::domain(config('app.domain'))->group(
|
|||||||
Route::get('/search/aircraft', [SearchController::class, 'aircraft'])->name('search.aircraft');
|
Route::get('/search/aircraft', [SearchController::class, 'aircraft'])->name('search.aircraft');
|
||||||
Route::get('/search/airports', [SearchController::class, 'airports'])->name('search.airports');
|
Route::get('/search/airports', [SearchController::class, 'airports'])->name('search.airports');
|
||||||
|
|
||||||
|
|
||||||
|
Route::get('/u/{username}', [FlightProfileController::class, 'view']);
|
||||||
|
|
||||||
require __DIR__.'/auth.php';
|
require __DIR__.'/auth.php';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user