my-idlers/app/Http/Controllers/LocationsController.php
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

46 lines
983 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Locations;
use Illuminate\Http\Request;
class LocationsController extends Controller
{
public function index()
{
$locations = Locations::all();
return view('locations.index', compact(['locations']));
}
public function create()
{
return view('locations.create');
}
public function store(Request $request)
{
$request->validate([
'location_name' => 'required|min:2'
]);
Locations::create([
'name' => $request->location_name
]);
return redirect()->route('locations.index')
->with('success', 'Location Created Successfully.');
}
public function destroy(Locations $location)
{
$items = Locations::find($location->id);
$items->delete();
return redirect()->route('locations.index')
->with('success', 'Location was deleted Successfully.');
}
}