So beheben Sie die Update-Funktion für die Einzelansichtsseite laravel -11 crudPhp

PHP-Programmierer chatten hier
Anonymous
 So beheben Sie die Update-Funktion für die Einzelansichtsseite laravel -11 crud

Post by Anonymous »

Ich versuche, eine Einzelansichtsseite form.blade.php zu erreichen, die sich mit der Funktion zum Erstellen, Bearbeiten und Aktualisieren in Laravel 11 befasst.
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



create-form-layout.blade.php

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 }}



Controller

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.');
}
}
Wenn ich das Formular im Bearbeitungszustand absende, wird die Seite auf eine leere weiße Seite mit der URL http://localhost/my-app/public/categori ... c&_method= umgeleitet PUT&name=Jumbo&code=n . und nein führt zu dem, was passiert. Ich habe versucht zu protokollieren, dass die Aktualisierungsfunktion nicht erreicht wurde und keine zugehörigen Daten im Protokoll enthalten sind.

@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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post