Created FilamentController & Filament Model + Views

This commit is contained in:
2025-03-10 21:47:57 +01:00
parent fbf0a3b6ca
commit 6a199c3a3c
14 changed files with 544 additions and 14 deletions
+77 -7
View File
@@ -3,6 +3,10 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Filament;
use App\Models\Color;
use App\Models\FilamentType;
use App\Models\Manufacturer;
class FilamentController extends Controller
{
@@ -11,7 +15,10 @@ class FilamentController extends Controller
*/
public function index()
{
//
// show all filaments
$filaments = Filament::all();
$manufacturers = Manufacturer::all();
return view('filaments.index', ['filaments' => $filaments, 'manufacturers' => $manufacturers]);
}
/**
@@ -19,7 +26,11 @@ class FilamentController extends Controller
*/
public function create()
{
//
// create a new filament
$manufacturers = Manufacturer::all();
$types = FilamentType::all();
$colors = Color::all();
return view('filaments.create', compact('manufacturers', 'types', 'colors'));
}
/**
@@ -27,7 +38,30 @@ class FilamentController extends Controller
*/
public function store(Request $request)
{
//
// store a new filament
$request->validate([
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'color_id' => 'required|exists:colors,id',
'type_id' => 'required|exists:filament_types,id',
'manufacturer_id' => 'required|exists:manufacturers,id',
'weight' => 'required|numeric',
'price' => 'nullable|decimal:2',
'diameter' => 'required|decimal:2'
]);
$filament = new Filament();
$filament->name = $request->name;
$filament->description = $request->description;
$filament->color_id = $request->color_id;
$filament->type_id = $request->type_id;
$filament->manufacturer_id = $request->manufacturer_id;
$filament->weight = $request->weight;
$filament->price = $request->price;
$filament->diameter = $request->diameter;
$filament->save();
return redirect()->route('filaments.index')->with('success', 'Filament created successfully.');
}
/**
@@ -35,7 +69,12 @@ class FilamentController extends Controller
*/
public function show(string $id)
{
//
// show a specific filament
$filament = Filament::find($id);
$manufacturer = Manufacturer::find($filament->manufacturer_id);
$type = FilamentType::find($filament->type_id);
$color = Color::find($filament->color_id);
return view('filaments.show', compact('filament', 'manufacturer', 'type', 'color'));
}
/**
@@ -43,7 +82,12 @@ class FilamentController extends Controller
*/
public function edit(string $id)
{
//
// edit a specific filament
$filament = Filament::find($id);
$manufacturers = Manufacturer::all();
$types = FilamentType::all();
$colors = Color::all();
return view('filaments.edit', compact('filament', 'manufacturers', 'types', 'colors'));
}
/**
@@ -51,7 +95,30 @@ class FilamentController extends Controller
*/
public function update(Request $request, string $id)
{
//
// update a specific filament
$request->validate([
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'color_id' => 'required|exists:colors,id',
'type_id' => 'required|exists:filament_types,id',
'manufacturer_id' => 'required|exists:manufacturers,id',
'weight' => 'required|numeric',
'price' => 'nullable|decimal:2',
'diameter' => 'required|decimal:2'
]);
$filament = Filament::find($id);
$filament->name = $request->name;
$filament->description = $request->description;
$filament->color_id = $request->color_id;
$filament->type_id = $request->type_id;
$filament->manufacturer_id = $request->manufacturer_id;
$filament->weight = $request->weight;
$filament->price = $request->price;
$filament->diameter = $request->diameter;
$filament->save();
return redirect()->route('filaments.show', $filament->id)->with('success', 'Filament updated successfully.');
}
/**
@@ -59,6 +126,9 @@ class FilamentController extends Controller
*/
public function destroy(string $id)
{
//
// delete a specific filament
$filament = Filament::find($id);
$filament->delete();
return redirect()->route('filaments.index')->with('success', 'Filament deleted successfully.');
}
}
@@ -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.');
}
}