Außer das Update funktioniert
form.blade.php
Code: Select all
{{ isset($category) ? 'Edit Category' : 'Create Category' }}
Category
@error('name')
{{ $message }}
@enderror
Code
@error('code')
{{ $message }}
@enderror
{{ isset($category) ? 'Update' : 'Save' }}
List
Code: Select all
@props(['action', 'method' => 'POST', 'title', 'leftInputs', 'rightInputs', 'listHref' => '#','freeSlot'=>''])
@csrf
@if (strtoupper($method) !== 'POST')
{{-- --}}
@method($method)
@endif
{{ $title }}
{{ $leftInputs }}
{{ $rightInputs }}
merge(['class' => ''])}}>
{{ $freeSlot }}
{{ $buttons }}
Code: Select all
class CategoryController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$dataProvider = Category::all();
return view('categories.index', compact('dataProvider'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('categories.form', [
'action' => route('categories.store'),
'method' => 'POST',
'category' => null, // No category data for create
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(StoreCategoryRequest $request)
{
Category::create($request->validated());
return redirect()->route('categories.index')->with('success', 'Category created successfully.');
}
/**
* Display the specified resource.
*/
public function show(Category $category)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$category = Category::findOrFail($id);
$route = route('categories.update', $category->id);
return view('categories.form', [
'action' => $route,
'method' => 'PUT',
'category' => $category, // Pass existing category data for edit
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Category $category)
{
logger('Update function reached', ['data' => $request->all()]);
$category->update($request->only(['name', 'code']));
return redirect()->route('categories.index')->with('success', 'Category updated successfully.');
}
public function destroy(Category $category)
{
$category->delete();
return redirect()->route('categories.index')->with('success', 'Category deleted successfully.');
}
}
@dump($action) result "http://localhost/ my-app/public/categories/24" // resources\views/components/create-form-layout.blade.php
Ich kann nicht finde das Problem ist