Cleaned up controllers with for PHP 8

This commit is contained in:
Ramon Robben 2021-06-06 20:17:52 +02:00
parent 2bf11d23ef
commit 02a2449350
5 changed files with 28 additions and 292 deletions

View file

@ -2,28 +2,19 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
class HomeController extends Controller class HomeController extends Controller
{ {
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct() public function __construct()
{ {
$this->middleware('auth'); $this->middleware('auth');
} }
/** /** Show the application dashboard. */
* Show the application dashboard. public function index(Request $request): Renderable
*
* @param Request $request
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request)
{ {
//set cookie as extra layer of defense against users that make multiple accounts //set cookie as extra layer of defense against users that make multiple accounts
setcookie('4b3403665fea6' , base64_encode(1) , time() + (20 * 365 * 24 * 60 * 60)); setcookie('4b3403665fea6' , base64_encode(1) , time() + (20 * 365 * 24 * 60 * 60));

View file

@ -11,12 +11,8 @@ use Illuminate\Support\Facades\Auth;
class NotificationController extends Controller class NotificationController extends Controller
{ {
/** /** Display a listing of the resource. */
* Display a listing of the resource. public function index(): View|Factory
*
* @return Factory|View
*/
public function index()
{ {
$notifications = Auth::user()->notifications()->paginate(); $notifications = Auth::user()->notifications()->paginate();
@ -25,34 +21,8 @@ class NotificationController extends Controller
]); ]);
} }
/** /** Display the specified resource. */
* Show the form for creating a new resource. public function show(string $id): View|Factory
*
* @return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param string $id
* @return Factory|View
*/
public function show($id)
{ {
$notification = Auth::user()->notifications()->findOrFail($id); $notification = Auth::user()->notifications()->findOrFail($id);
@ -61,38 +31,4 @@ class NotificationController extends Controller
'notification' => $notification 'notification' => $notification
]); ]);
} }
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
} }

View file

@ -14,12 +14,8 @@ use Illuminate\Support\Facades\Hash;
class ProfileController extends Controller class ProfileController extends Controller
{ {
/** /** Display a listing of the resource. */
* Display a listing of the resource. public function index(): View|Factory
*
* @return Factory|View
*/
public function index()
{ {
return view('profile.index')->with([ return view('profile.index')->with([
'user' => Auth::user(), 'user' => Auth::user(),
@ -28,57 +24,8 @@ class ProfileController extends Controller
]); ]);
} }
/** /** Update the specified resource in storage. */
* Show the form for creating a new resource. public function update(Request $request, int $id): RedirectResponse
*
* @return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return RedirectResponse
*/
public function update(Request $request, int $id)
{ {
//prevent other users from editing a user //prevent other users from editing a user
if ($id != Auth::user()->id) dd(401); if ($id != Auth::user()->id) dd(401);
@ -136,15 +83,4 @@ class ProfileController extends Controller
return redirect()->route('profile.index')->with('success' , 'profile updated'); return redirect()->route('profile.index')->with('success' , 'profile updated');
} }
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
} }

View file

@ -22,26 +22,16 @@ use Illuminate\Support\Facades\Auth;
class ServerController extends Controller class ServerController extends Controller
{ {
/** Display a listing of the resource. */
public function index(): View|Factory
/**
* Display a listing of the resource.
*
* @return Factory|View
*/
public function index()
{ {
return view('servers.index')->with([ return view('servers.index')->with([
'servers' => Auth::user()->Servers 'servers' => Auth::user()->Servers
]); ]);
} }
/** /** Show the form for creating a new resource. */
* Show the form for creating a new resource. public function create(): View|Factory|RedirectResponse
*
* @return Factory|View|RedirectResponse
*/
public function create()
{ {
//limit //limit
if (Auth::user()->Servers->count() >= Auth::user()->server_limit) { if (Auth::user()->Servers->count() >= Auth::user()->server_limit) {
@ -63,13 +53,8 @@ class ServerController extends Controller
]); ]);
} }
/** /** Store a newly created resource in storage. */
* Store a newly created resource in storage. public function store(Request $request): RedirectResponse
*
* @param Request $request
* @return RedirectResponse
*/
public function store(Request $request)
{ {
$request->validate([ $request->validate([
"name" => "required|max:191", "name" => "required|max:191",
@ -89,7 +74,6 @@ class ServerController extends Controller
return redirect()->route('servers.index')->with('error', "You do not have the required amount of credits to create a new server!"); return redirect()->route('servers.index')->with('error', "You do not have the required amount of credits to create a new server!");
} }
//create server //create server
$egg = Egg::findOrFail($request->input('egg_id')); $egg = Egg::findOrFail($request->input('egg_id'));
$server = Auth::user()->servers()->create($request->all()); $server = Auth::user()->servers()->create($request->all());
@ -110,11 +94,7 @@ class ServerController extends Controller
return redirect()->route('servers.index')->with('success', 'server created'); return redirect()->route('servers.index')->with('success', 'server created');
} }
/** /** Quick Fix */
* Quick Fix
* @param Server $server
* @return RedirectResponse
*/
private function serverCreationFailed(Server $server): RedirectResponse private function serverCreationFailed(Server $server): RedirectResponse
{ {
$server->delete(); $server->delete();
@ -123,51 +103,14 @@ class ServerController extends Controller
return redirect()->route('servers.index')->with('error', 'No allocations satisfying the requirements for automatic deployment were found.'); return redirect()->route('servers.index')->with('error', 'No allocations satisfying the requirements for automatic deployment were found.');
} }
/** /** Remove the specified resource from storage. */
* Display the specified resource. public function destroy(Server $server): RedirectResponse
*
* @param Server $server
* @return Response
*/
public function show(Server $server)
{ {
// try {
} $server->delete();
return redirect()->route('servers.index')->with('success', 'server removed');
/** } catch (\Exception $e) {
* Show the form for editing the specified resource. return redirect()->route('servers.index')->with('error', 'An exception has occurred while trying to remove a resource');
* }
* @param Server $server
* @return Response
*/
public function edit(Server $server)
{
//
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Server $server
* @return Response
*/
public function update(Request $request, Server $server)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param Server $server
* @return RedirectResponse
* @throws Exception
*/
public function destroy(Server $server)
{
$server->delete();
return redirect()->route('servers.index')->with('success', 'server removed');
} }
} }

View file

@ -11,12 +11,8 @@ use Illuminate\Http\Response;
class StoreController extends Controller class StoreController extends Controller
{ {
/** /** Display a listing of the resource. */
* Display a listing of the resource. public function index(): View|Factory|Response|Application
*
* @return Application|Factory|View|Response
*/
public function index()
{ {
$isPaypalSetup = false; $isPaypalSetup = false;
if (env('PAYPAL_SECRET') && env('PAYPAL_CLIENT_ID')) $isPaypalSetup = true; if (env('PAYPAL_SECRET') && env('PAYPAL_CLIENT_ID')) $isPaypalSetup = true;
@ -26,70 +22,4 @@ class StoreController extends Controller
'isPaypalSetup' => $isPaypalSetup 'isPaypalSetup' => $isPaypalSetup
]); ]);
} }
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
} }