59 lines
1.4 KiB
PHP
Executable File
59 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Country;
|
|
use App\Models\Region;
|
|
use Illuminate\Http\Request;
|
|
|
|
class RegionController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$regions = Region::orderBy('id','desc')->get();
|
|
|
|
return view('region.index', compact('regions'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$countries = Country::all();
|
|
|
|
return view('region.create', compact('countries'));
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'country_id' => 'required',
|
|
]);
|
|
Region::create($request->post());
|
|
|
|
return redirect()->route('regions.index')->with('success','region has been created successfully.');
|
|
}
|
|
|
|
public function edit(Region $region)
|
|
{
|
|
$countries = Country::all();
|
|
|
|
return view('region.edit',compact('region', 'countries'));
|
|
}
|
|
|
|
public function update(Request $request, Region $region)
|
|
{
|
|
$request->validate([
|
|
'country_id' => 'required',
|
|
]);
|
|
|
|
$region->fill($request->post())->save();
|
|
|
|
return redirect()->route('regions.index')->with('success','regions Has Been updated successfully');
|
|
}
|
|
|
|
public function destroy(Region $region)
|
|
{
|
|
$region->delete();
|
|
return redirect()->route('regions.index')->with('success','regions has been deleted successfully');
|
|
}
|
|
}
|