mirror of
https://github.com/cp6/my-idlers.git
synced 2024-11-16 23:42:32 +01:00
3bd9d5890c
Updated all destroy() methods to directly delete the resource rather than fetch from database which turns out is not needed
86 lines
2.0 KiB
PHP
86 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Server;
|
|
use App\Models\Yabs;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class YabsController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('yabs.index', ['yabs' => Yabs::allYabs()]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
abort(404);//Use new YABS json output POST method -s "URL"
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
abort(404);//Storing YABS now done through APiController
|
|
}
|
|
|
|
public function show(Yabs $yab)
|
|
{
|
|
return view('yabs.show', ['yabs' => Yabs::yabs($yab->id)]);
|
|
}
|
|
|
|
public function destroy(Yabs $yab)
|
|
{
|
|
$yab->delete();
|
|
|
|
if (Server::serverYabsAmount($yab->server_id) === 0) {
|
|
DB::table('servers')
|
|
->where('id', $yab->server_id)
|
|
->update(['has_yabs' => 0]);
|
|
}
|
|
|
|
Cache::forget('all_yabs');
|
|
Cache::forget("yabs.{$yab->id}");
|
|
|
|
return redirect()->route('yabs.index')
|
|
->with('success', 'YABS was deleted Successfully.');
|
|
}
|
|
|
|
public function chooseYabsCompare()
|
|
{
|
|
$all_yabs = Yabs::allYabs();
|
|
|
|
if (isset($all_yabs[1])){
|
|
return view('yabs.choose-compare', compact('all_yabs'));
|
|
}
|
|
|
|
return redirect()->route('yabs.index')
|
|
->with('error', 'You need atleast 2 YABS to do a compare');
|
|
}
|
|
|
|
public function compareYabs(string $yabs1, string $yabs2)
|
|
{
|
|
$yabs1_data = Yabs::yabs($yabs1);
|
|
|
|
if (is_null($yabs1_data)) {
|
|
abort(404);
|
|
}
|
|
|
|
$yabs2_data = Yabs::yabs($yabs2);
|
|
|
|
if (is_null($yabs2_data)) {
|
|
abort(404);
|
|
}
|
|
|
|
return view('yabs.compare', compact('yabs1_data', 'yabs2_data'));
|
|
}
|
|
|
|
public function yabsToJson(Yabs $yab): array
|
|
{
|
|
$all_yabs = Yabs::yabs($yab->id)[0];
|
|
return Yabs::buildYabsArray($all_yabs);
|
|
}
|
|
|
|
}
|