Created FilamentController & Filament Model + Views
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Manufacturer;
|
||||
|
||||
class ManufacturerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// show all manufacturers
|
||||
$manufacturers = Manufacturer::all();
|
||||
return view('manufacturers.index', compact('manufacturers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
// create a new manufacturer
|
||||
return view('manufacturers.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// store a new manufacturer
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255'
|
||||
]);
|
||||
|
||||
$manufacturer = new Manufacturer();
|
||||
$manufacturer->name = $request->name;
|
||||
$manufacturer->description = $request->description;
|
||||
$manufacturer->website = $request->website;
|
||||
$manufacturer->save();
|
||||
|
||||
return redirect()->route('manufacturers.index')->with('success', 'Manufacturer created successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
// show a specific manufacturer
|
||||
$manufacturer = Manufacturer::find($id);
|
||||
return view('manufacturers.show', compact('manufacturer'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
// edit a specific manufacturer
|
||||
$manufacturer = Manufacturer::find($id);
|
||||
return view('manufacturers.edit', compact('manufacturer'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
// update a specific manufacturer
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255'
|
||||
]);
|
||||
|
||||
$manufacturer = Manufacturer::find($id);
|
||||
$manufacturer->name = $request->name;
|
||||
$manufacturer->description = $request->description;
|
||||
$manufacturer->website = $request->website;
|
||||
$manufacturer->save();
|
||||
return redirect()->route('manufacturers.show', $manufacturer->id)->with('success', 'Manufacturer updated successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
// delete a specific manufacturer
|
||||
$manufacturer = Manufacturer::find($id);
|
||||
$manufacturer->delete();
|
||||
return redirect()->route('manufacturers.index')->with('success', 'Manufacturer deleted successfully.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user