122 lines
2.7 KiB
PHP
122 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Status;
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
use Illuminate\Contracts\View\Factory;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Routing\Redirector;
|
|
|
|
class StatusController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @param Request $request
|
|
* @return View
|
|
*/
|
|
public function index(Request $request) : view
|
|
{
|
|
$status = Status::all();
|
|
|
|
return view("state.index", [ "states" => $status]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @param Request $request
|
|
* @return Application|Factory|View|RedirectResponse
|
|
*/
|
|
public function create(Request $request)
|
|
{
|
|
return \view("state.create");
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param Request $request
|
|
* @return RedirectResponse
|
|
*/
|
|
public function store(Request $request) : RedirectResponse
|
|
{
|
|
$rawstatus = $request->validate([
|
|
'name' => 'required|string'
|
|
]);
|
|
$status = new Status($rawstatus);
|
|
|
|
if($status->save()) {
|
|
return redirect()->route("index");
|
|
}
|
|
|
|
return redirect()->route("error");
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param Status $status
|
|
* @return View
|
|
*/
|
|
public function show(Status $status) : View
|
|
{
|
|
return view("state.show-status")->with([
|
|
"state" => $status
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param Status $status
|
|
* @return Response
|
|
*/
|
|
public function edit(Status $status): Response
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param Request $request
|
|
* @param Status $status
|
|
* @return View
|
|
*/
|
|
public function update(Request $request, Status $status): View
|
|
{
|
|
$data = $request->validate([
|
|
'name' => 'required|string'
|
|
]);
|
|
$status->update($data);
|
|
|
|
if(!$status->save()){
|
|
return view("state.show-status", [ "states" => $status ]);
|
|
}else{
|
|
$states = Status::all();
|
|
|
|
return view("state.index", ['states' => $states, "success" => "Opdaterede state"]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param Status $status
|
|
* @return RedirectResponse
|
|
*/
|
|
public function destroy(Status $status): RedirectResponse
|
|
{
|
|
$status->posts()->delete();
|
|
|
|
$status->delete();
|
|
return redirect()->route("index");
|
|
|
|
}
|
|
}
|