Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anders 2020-07-01 11:44:20 +02:00
commit 2368573ee7
8 changed files with 71 additions and 49 deletions

View File

@ -28,8 +28,11 @@ class EventController extends Controller
*/
public function index(Request $request)
{
$events = Event::query()->paginate($request->input("limit", 20));
//returns the function with events index page and a parameter of events.
//also Response::detect checks screen size to determine if user is on a computer or mobile.
return Response::detect("events.index", [ "events" => $events]);
}
@ -40,6 +43,7 @@ class EventController extends Controller
*/
public function create()
{
//returns "create event" blade
return Response::detect("events.create");
}
@ -57,6 +61,7 @@ class EventController extends Controller
"date" => "required"
]);
//creates a new Event model with the given parameter
$event = new Event($requestBody);
$saved = $event->save();

View File

@ -2,10 +2,15 @@
namespace App\Http\Controllers;
use App\WashingMachine;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\WashingReservation;
use Illuminate\View\View;
class WashingReservationController extends Controller
{
@ -24,11 +29,11 @@ class WashingReservationController extends Controller
* Display a listing of the resource.
*
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Application|Factory|View
*/
public function index(Request $request)
{
$reservations = WashingReservation::query()->paginate($request->query("page", 1));
$reservations = WashingReservation::query()->paginate($request->query("limit", 20));
return Response::detect("washing-reservations.index", [ "reservations" => $reservations]);
}
@ -36,23 +41,25 @@ class WashingReservationController extends Controller
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Application|Factory|View
*/
public function create()
{
return Response::detect("washing-reservations.create");
$machines = WashingMachine::all();
return Response::detect("washing-reservations.create", [ 'machines' => $machines ]);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Application|Factory|View
*/
public function store(Request $request)
{
$data = $request->validate([
"time" => "required"
"time" => "required",
"machine" => "required"
]);
$machineReservation = new WashingReservation($data);
@ -65,7 +72,7 @@ class WashingReservationController extends Controller
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Application|Factory|View
*/
public function show($id)
{
@ -80,11 +87,14 @@ class WashingReservationController extends Controller
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Application|Factory|View
*/
public function edit($id)
{
return Response::detect("washing-reservations.edit");
$reservation = WashingReservation::query()->find($id);
$machines = WashingMachine::all();
return Response::detect("washing-reservations.edit", ['washing_reservation' => $reservation, 'machines' => $machines ]);
}
/**
@ -92,12 +102,13 @@ class WashingReservationController extends Controller
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Application|Factory|View
*/
public function update(Request $request, $id)
{
$data = $request->validate([
"time" => "required"
"time" => "required",
"machine" => "required"
]);
$machineReservation = WashingReservation::find($id);
@ -106,8 +117,8 @@ class WashingReservationController extends Controller
$machineReservation->save();
return Response::detect("washing-reservations.edit", [
"washingReservation" => $machineReservation
return Response::detect("washing-reservations.update", [
"washing_reservation" => $machineReservation
]);
}
@ -115,13 +126,15 @@ class WashingReservationController extends Controller
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return RedirectResponse
*/
public function destroy($id)
{
$machineReservation = WashingReservation::find($id);
$machineReservation->delete();
return Response::detect("washing-reservations.delete");
$reservations = WashingReservation::query()->paginate( 20);
return redirect()->route("washing-reservations.index", [ "reservations" => $reservations]);
}
}

View File

@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class WashingReservation extends Model
{
//
protected $fillable = [
'time', 'machine'
];
}

View File

@ -17,6 +17,8 @@ class CreateWashingReservations extends Migration
$table->id();
$table->timestamp("time");
$table->timestamps();
$table->unsignedBigInteger('machine');
$table->foreign("machine")->references('id')->on('washing_machines');
});
}

View File

@ -6,21 +6,21 @@
@endsection
@section("path")
<a href="{{ route('washing-reservations.create') }}" class="text-white">Opret Vaske Reservationer</a> /
<a href="{{ route('washing-reservations.create') }}" class="text-white">Opret Vaskemaskine Reservation</a> /
@endsection
@section("content")
<h1>Opret Booking:</h1>
<h1>Opret Reservation:</h1>
<form method="post" action="{{ route("washing-reservations.store") }}">
@csrf
<label for="name_first">Fornavn:</label>
<input type="text" name="name_first" id="name_first" required>
<label for="name_last">Efternavn:</label>
<input type="text" name="name_last" id="name_last" required>
<label for="tel">Telefon nr:</label>
<input type="tel" name="phone" id="tel" required>
<select name="machine_choice">
<option>Vaskemaskine 1</option>
<label for="time">Tidspunkt:</label>
<input type="datetime-local" name="time" id="time" required>
<label for="machine">Vaskemaskine:</label>
<select name="machine" id="machine" required>
<option disabled selected value> -- Vælg Vaskemaskine -- </option>
@foreach($machines as $machine)
<option value="{{ $machine->id }}">{{ $machine->name }}</option>
@endforeach
</select>
<input type="submit" class="btn btn-dark text-white" value="Opret">
</form>

View File

@ -6,22 +6,26 @@
@endsection
@section("path")
<a href="{{ route('washing-reservations.edit', ['id' => $reservations->id]) }}" class="text-white">Rediger Vaske Reservationer</a> /
<a href="{{ route('washing-reservations.edit', ['washing_reservation' => $washing_reservation]) }}" class="text-white">Rediger Vaske Reservationer</a> /
@endsection
@section("content")
<h1>Rediger Booking:</h1>
<form method="post" action="">
<form method="post" action="{{ route('washing-reservations.update', ['washing_reservation' => $washing_reservation ]) }}">
@csrf
<label for="name_first">Fornavn:</label>
<input type="text" name="name_first" id="name_first" value="{Fornavn}" required>
<label for="name_last">Efternavn:</label>
<input type="text" name="name_last" id="name_last" value="{Efternavn}" required>
<input type="password" id="password2" value="{Password}" required>
<label for="tel">Telefon nr:</label>
<input type="tel" name="phone" id="tel" value="{Telefon}" required>
<select>
<option>Vaskemaskine 1</option>
@method("put")
<label for="time">Tidspunkt:</label>
<input type="datetime-local" name="time" id="time" value="{{ $washing_reservation->time }}" required>
<label for="machine">Vaskemaskine:</label>
<select name="machine" id="machine" required>
<option disabled value> -- Vælg Vaskemaskine -- </option>
@foreach($machines as $machine)
@if($machine->id == $washing_reservation->machine)
<option selected value="{{ $machine->id }}">{{ $machine->name }}</option>
@else
<option value="{{ $machine->id }}">{{ $machine->name }}</option>
@endif
@endforeach
</select>
<input type="submit" class="btn btn-dark text-white" value="Rediger">
</form>

View File

@ -15,21 +15,17 @@
</div>
<table class="tbl mt-2">
<tr>
<th>Fornavn</th>
<th>Efternavn</th>
<th>Tlf nr</th>
<th>Vaskemaskine</th>
<th>Time</th>
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/pencil.svg') }}" alt="Update"></th>
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/trashcan.svg') }}" alt="Delete"></th>
</tr>
@foreach($reservations as $reservation)
<tr>
<td>{Fornavn}</td>
<td>{Efternavn}</td>
<td>{Tlf Nr}</td>
<td>{Vaskemaskine Nr.}</td>
<td><a href=""><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
<td><form method="post" action="" class="w-100 nostyle">
<td>{{ \App\WashingMachine::query()->find($reservation->machine)->name }}</td>
<td>{{ $reservation->time }}</td>
<td><a href="{{ route('washing-reservations.edit', ['washing_reservation' => $reservation]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
<td><form method="post" action="{{ route('washing-reservations.destroy', ['washing_reservation' => $reservation]) }}" class="w-100 nostyle">
@csrf
@method("delete")

View File

@ -2,13 +2,13 @@
@extends("admin.layout.header")
@section("title")
Vaske Reservationer - Rediger
Vaskemaskine Reservationer - Rediger
@endsection
@section("path")
<a href="{{ route('washing-reservations.edit') }}" class="text-white">Rediger Vaske Reservationer</a> /
<a href="{{ route('washing-reservations.edit', ['washing_reservation' => $washing_reservation]) }}" class="text-white">Rediger Vaskemaskine Reservationer</a> /
@endsection
@section("content")
Din Vaske Reservationer blev (ikke) redigeret.
Din Vaskemaskine Reservationer blev (ikke) redigeret.
@endsection