Created FilamentTypeController & FilamentType Model

This commit is contained in:
2025-03-10 19:28:46 +01:00
parent 9fd01ee43a
commit 21f33383ae
15 changed files with 404 additions and 5 deletions
@@ -0,0 +1,87 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\FilamentType;
class FilamentTypeController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$types = FilamentType::all();
return view('types.index', compact('types'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return view('types.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
$type = new FilamentType();
$type->name = $request->name;
$type->description = $request->description;
$type->save();
return redirect()->route('types.index');
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
// Show Single Type
$type = FilamentType::find($id);
return view('types.show', compact('type'));
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
$type = FilamentType::find($id);
return view('types.edit', compact('type'));
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
// Store updated type
$type = FilamentType::find($id);
$type->name = $request->name;
$type->description = $request->description;
$type->save();
return redirect()->route('types.show', $type->id);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
// Delete Type
$type = FilamentType::find($id);
$type->delete();
return redirect()->route('types.index')->with('success','Type deleted successfully.');
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Livewire;
use Livewire\Component;
use App\Models\FilamentType;
class CreateFilamentType extends Component
{
public $name = "";
public $decription = "";
public function save()
{
FilamentType::create(
$this->only(['name', 'description'])
);
session()->flash('status', 'Filament Type Created Successfully.');
return redirect()->route('filamenttype.list');
}
public function render()
{
return view('filamenttype.create');
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class FilamentType extends Model
{
protected $table = 'filament_types';
protected $fillable = [
'name',
'description',
];
}
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('filament_types', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name');
$table->string('description');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('filament_types');
}
};
+12
View File
@@ -11,6 +11,10 @@
--font-sans:
Inter, ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--color-accent: var(--color-rose-500);
--color-accent-content: var(--color-rose-500);
--color-accent-foreground: var(--color-white);
}
/*
@@ -31,6 +35,14 @@
}
}
@layer theme {
.dark {
--color-accent: var(--color-rose-500);
--color-accent-content: var(--color-rose-400);
--color-accent-foreground: var(--color-white);
}
}
[x-cloak] {
display: none;
}
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ $title ?? 'Page Title' }}</title>
</head>
<body>
{{ $slot }}
</body>
</html>
+4 -4
View File
@@ -5,10 +5,10 @@
<flux:brand href="{{ route('dashboard') }}" logo="https://fluxui.dev/img/demo/dark-mode-logo.png" name="Filament" class="max-lg:hidden! hidden dark:flex" />
<flux:navbar class="-mb-px max-lg:hidden">
<flux:navbar.item icon="home" href="{{ route('dashboard') }}" current>Dashboard</flux:navbar.item>
<flux:navbar.item icon="archive-box" href="#">Hersteller</flux:navbar.item>
<flux:navbar.item icon="circle-stack" href="#">Filamente</flux:navbar.item>
<flux:navbar.item icon="chart-pie" badge="12" href="#">Arten</flux:navbar.item>
<flux:navbar.item icon="home" href="{{ route('dashboard') }}">Dashboard</flux:navbar.item>
<flux:navbar.item icon="archive-box" href="#">Manufacturers</flux:navbar.item>
<flux:navbar.item icon="circle-stack" href="#">Filaments</flux:navbar.item>
<flux:navbar.item icon="chart-pie" href="{{ route('types.index') }}">Types</flux:navbar.item>
</flux:navbar>
<flux:spacer />
@@ -0,0 +1,43 @@
{{-- Credit: Lucide (https://lucide.dev) --}}
@props([
'variant' => 'outline',
])
@php
if ($variant === 'solid') {
throw new \Exception('The "solid" variant is not supported in Lucide.');
}
$classes = Flux::classes('shrink-0')
->add(match($variant) {
'outline' => '[:where(&)]:size-6',
'solid' => '[:where(&)]:size-6',
'mini' => '[:where(&)]:size-5',
'micro' => '[:where(&)]:size-4',
});
$strokeWidth = match ($variant) {
'outline' => 2,
'mini' => 2.25,
'micro' => 2.5,
};
@endphp
<svg
{{ $attributes->class($classes) }}
data-flux-icon
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="{{ $strokeWidth }}"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
data-slot="icon"
>
<circle cx="12" cy="12" r="1" />
<circle cx="19" cy="12" r="1" />
<circle cx="5" cy="12" r="1" />
</svg>
+42
View File
@@ -0,0 +1,42 @@
{{-- Credit: Lucide (https://lucide.dev) --}}
@props([
'variant' => 'outline',
])
@php
if ($variant === 'solid') {
throw new \Exception('The "solid" variant is not supported in Lucide.');
}
$classes = Flux::classes('shrink-0')
->add(match($variant) {
'outline' => '[:where(&)]:size-6',
'solid' => '[:where(&)]:size-6',
'mini' => '[:where(&)]:size-5',
'micro' => '[:where(&)]:size-4',
});
$strokeWidth = match ($variant) {
'outline' => 2,
'mini' => 2.25,
'micro' => 2.5,
};
@endphp
<svg
{{ $attributes->class($classes) }}
data-flux-icon
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="{{ $strokeWidth }}"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
data-slot="icon"
>
<path d="M18 6 6 18" />
<path d="m6 6 12 12" />
</svg>
+1 -1
View File
@@ -28,7 +28,7 @@
<!-- Page Heading -->
@if (isset($header) || isset($headeraction))
<div class="bg-white dark:bg-zinc-700 shadow-sm ">
<div class="flex justify-between max-w-7xl mx-auto">
<div class="flex justify-between max-w-7xl mx-auto items-center">
@if (isset($header))
<x-header>
{{ $header }}
+36
View File
@@ -0,0 +1,36 @@
<x-app-layout>
<x-slot name="header">
{{ __('Create Types') }}
</x-slot>
<x-slot name="headeraction">
<div class="flex gap-4 justify-end">
<a href="{{ route('types.index') }}" class=" text-zinc-50 hover:text-zinc-300 font-bold text-base py-2 px-4 rounded cursor-pointer">Back</a>
<a href="{{ route('types.store') }}" onclick="event.preventDefault(); document.getElementById('create-type-form').submit();" class="bg-green-500 hover:bg-green-700 text-zinc-700 hover:text-white font-bold text-base py-2 px-4 rounded cursor-pointer">Submit</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-zinc-700 p-4 overflow-hidden shadow-xl sm:rounded-lg">
<form id="create-type-form" class="flex flex-col gap-6" method="POST" action="{{ route('types.store') }}">
@csrf
<div class="form-group flex flex-col">
<label for="name" class="text-lg ">Name</label>
<input type="text" id="name" name="name" class="form-control bg-white dark:bg-zinc-800 border-zinc-50 dark:border-zinc-600 rounded" required="">
</div>
<div class="form-group flex flex-col">
<label for="description">Description</label>
<textarea name="description" class="form-control bg-white dark:bg-zinc-800 border-zinc-50 dark:border-zinc-600 rounded" required=""></textarea>
</div>
<div class="flex justify-end gap-4">
<a href="{{ route('types.index') }}" class="bg-zinc-500 hover:bg-zinc-700 text-zinc-800 hover:text-white font-bold py-2 px-4 rounded cursor-pointer">Cancel</a>
<button type="submit" class="bg-green-500 hover:bg-green-700 text-zinc-800 hover:text-white font-bold py-2 px-4 rounded cursor-pointer">Submit</button>
</div>
</form>
</div>
</div>
</div>
</x-app-layout>
+30
View File
@@ -0,0 +1,30 @@
<x-app-layout>
<x-slot name="header">
{{ __('Create Types') }}
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-zinc-700 p-4 overflow-hidden shadow-xl sm:rounded-lg">
<form id="update-type-form" class="flex flex-col gap-6" method="POST" action="{{ route('types.update', $type->id) }}">
@csrf
@method('PUT')
<div class="form-group flex flex-col">
<label for="name" class="text-lg ">Name</label>
<input type="text" id="name" name="name" class="form-control bg-white dark:bg-zinc-800 border-zinc-50 dark:border-zinc-600 rounded" required="" value="{{ $type->name }}">
</div>
<div class="form-group flex flex-col">
<label for="description">Description</label>
<textarea name="description" class="form-control bg-white dark:bg-zinc-800 border-zinc-50 dark:border-zinc-600 rounded" required="" value="{{ $type->description }}"></textarea>
</div>
<div class="flex justify-end gap-4">
<a href="{{ route('types.index') }}" class="bg-zinc-500 hover:bg-zinc-700 text-zinc-800 hover:text-white font-bold py-2 px-4 rounded cursor-pointer">Cancel</a>
<button type="submit" class="bg-green-500 hover:bg-green-700 text-zinc-800 hover:text-white font-bold py-2 px-4 rounded cursor-pointer">Submit</button>
</div>
</form>
</div>
</div>
</div>
</x-app-layout>
+29
View File
@@ -0,0 +1,29 @@
<x-app-layout>
<x-slot name="header">
{{ __('Types') }}
</x-slot>
<x-slot name="headeraction">
<div class="flex gap-4 justify-end">
<a href="{{ route('types.create') }}" class="bg-zinc-500 hover:bg-green-500 text-zinc-50 hover:text-zinc-700 font-bold text-base py-2 px-4 rounded cursor-pointer">Create</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-zinc-700 overflow-hidden shadow-xl sm:rounded-lg">
<ul class="">
<li class="flex gap-6 bg-zinc-50 dark:bg-zinc-900 p-2 px-4"><div class="">ID</div><div class="">Name</div><div class="">Options</div></li>
@foreach ($types as $type)
<li class="flex gap-6 py-3 px-4 items-center">
<div class="p-2">{{ $type->id }}</div>
<div class="p-2"><a href="/types/{{ $type->id }}">{{ $type->name }}</a></div>
<div class="px-2"><a href="{{ route('types.edit', $type->id) }}"><flux:icon.ellipsis class="hover:text-zinc-50 hover:bg-zinc-500 stroke-3 rounded "/></a></div>
</li>
@endforeach
</ul>
</div>
</div>
</div>
</x-app-layout>
+31
View File
@@ -0,0 +1,31 @@
<x-app-layout>
<x-slot name="header">
{{ $type->name }}
</x-slot>
<x-slot name="headeraction">
<div class="flex gap-4 justify-end">
<a href="{{ route('types.index') }}" class=" text-zinc-50 hover:text-zinc-300 font-bold text-base py-2 px-4 rounded cursor-pointer">Back</a>
<a href="{{ route('types.edit', $type->id) }}" class="bg-zinc-500 hover:bg-zinc-700 text-zinc-50 hover:text-white font-bold text-base py-2 px-4 rounded cursor-pointer">Edit</a>
<a href="{{ route('types.destroy', $type->id) }}" onclick="event.preventDefault(); document.getElementById('delete-form-{{ $type->id }}').submit();" class="bg-red-500 hover:bg-red-500 text-zinc-50 hover:text-white font-bold text-base py-2 px-4 rounded cursor-pointer">Delete</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-zinc-700 overflow-hidden shadow-xl sm:rounded-lg">
<div class="p-4">
<div class="text-lg font-bold">Description</div>
<div class="p-4">
{{ $type->description }}
</div>
</div>
<form id="delete-form-{{ $type->id }}" method="POST" action="{{ route('types.destroy', $type->id) }}" class="hidden">
@csrf
@method('DELETE')
</form>
</div>
</div>
</div>
</x-app-layout>
+7
View File
@@ -1,6 +1,7 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FilamentTypeController;
Route::get('/', function () {
return view('welcome');
@@ -11,7 +12,13 @@ Route::middleware([
config('jetstream.auth_session'),
'verified',
])->group(function () {
// Dashboard
Route::get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
// Filament Types
Route::resource('types', FilamentTypeController::class);
});