mirror of
https://github.com/cp6/my-idlers.git
synced 2024-11-16 23:42:32 +01:00
e31a785844
Updated destroy() methods for delete condition If not true then return with the error alert
52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\OS;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class OsController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$os = OS::allOS();
|
|
return view('os.index', compact(['os']));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('os.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'os_name' => 'required|string|min:2|max:255'
|
|
]);
|
|
|
|
OS::create([
|
|
'name' => $request->os_name
|
|
]);
|
|
|
|
Cache::forget('operating_systems');
|
|
|
|
return redirect()->route('os.index')
|
|
->with('success', 'OS Created Successfully.');
|
|
}
|
|
|
|
public function destroy(OS $o)
|
|
{
|
|
if ($o->delete()) {
|
|
Cache::forget('operating_systems');
|
|
|
|
return redirect()->route('os.index')
|
|
->with('success', 'OS was deleted Successfully.');
|
|
}
|
|
|
|
return redirect()->route('os.index')
|
|
->with('error', 'OS was not deleted.');
|
|
|
|
}
|
|
}
|