Added more routes.

This commit is contained in:
Sebastian Davaris 2020-06-15 08:59:15 +02:00
parent 2f0ec75278
commit 07405d575d
7 changed files with 92 additions and 17 deletions

View File

@ -9,6 +9,17 @@ use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function __construct()
{
$this->middleware([ "auth" ])->only("logout");
$this->middleware([ "guest" ])->only("login");
$this->middleware([ "permission:user.list", "role:admin" ])->only("index");
$this->middleware([ "permission:user.show", "role:admin" ])->only("show");
$this->middleware([ "permission:user.edit", "role:admin" ])->only([ "edit", "update" ]);
$this->middleware([ "permission:user.delete", "role:admin" ])->only("delete");
}
/**
* Display a listing of the resource.
*

View File

@ -3,60 +3,75 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\WashingReservation;
class WashingReservationController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
public function index(Request $request)
{
//
$reservations = WashingReservation::query()->paginate($request->query("page", 1));
return view("washing-reservation.index");
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create()
{
//
return view("washing-reservation.create");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function store(Request $request)
{
//
$data = $request->validate([
"time" => "required"
]);
$machineReservation = new WashingReservation($data);
$machineReservation->save();
return view("washing-reservation.store");
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show($id)
{
//
$machineReservation = WashingReservation::find($id);
return view("washing-reservation.show", [
"machineReservation" => $machineReservation
]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function edit($id)
{
//
return view("washing-reservation.edit");
}
/**
@ -64,21 +79,36 @@ class WashingReservationController extends Controller
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function update(Request $request, $id)
{
//
$data = $request->validate([
"time" => "required"
]);
$machineReservation = WashingReservation::find($id);
$machineReservation->update($data);
$machineReservation->save();
return view("washing-reservation.edit", [
"washingReservation" => $machineReservation
]);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function destroy($id)
{
//
$machineReservation = WashingReservation::find($id);
$machineReservation->delete();
return view("washing-reservation.delete");
}
}

View File

@ -63,5 +63,9 @@ class Kernel extends HttpKernel
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
];
}

View File

@ -72,7 +72,7 @@ class RouteServiceProvider extends ServiceProvider
*/
protected function mapApiRoutes()
{
Route::prefix('api')
Route::prefix('api/v1')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));

Binary file not shown.

View File

@ -0,0 +1,27 @@
@extends('layout.base')
@section("title")
Opret Bruger
@endsection
@section('content')
<div>
<form action="{{ route("users.store") }}" method="post">
@csrf
<label for="name_first">First Name</label>
<input id="name_first" type="text" name="name_first">
<label for="name_last">Last Name</label>
<input id="name_last" type="text" name="name_last">
<label for="email">Email</label>
<input id="email" type="email" name="email">
<label for="password">Password</label>
<input id="password" type="password" name="password">
<input type="submit" value="Opret">
</form>
</div>
@endsection

View File

@ -18,7 +18,8 @@ use Illuminate\Support\Facades\Route;
//});
Route::middleware(["auth"])->group(function () {
Route::resource("washing-machines", "WashingMachineController");
Route::resource("washing-reservations", "WashingReservationController");
});
Route::get("/", "RootController@index")->name("root.index");
@ -26,3 +27,5 @@ Route::get("/", "RootController@index")->name("root.index");
Route::get("/login", "UserController@login")->name("user.login");
Route::get("/logout", "UserController@logout")->name("user.logout");
Route::resource("users", "UserController");