我正在嘗試通過 crud 編輯來編輯我的類別,我想我在控制器和路由中都做對了,但是我一直收到錯誤 404 頁面未找到,只要我點擊按鈕更改類別
這是我的控制器
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$category=Category::all();
return view('categorie.categorie', compact('category'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('categorie.crea');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $req)
{
$category = Category::create([
'nome'=>$req->nome
]);
return redirect()->back()->with('message', 'Categoria inserita correttamente');
}
/**
* Display the specified resource.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function show(Category $category)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function edit(Category $category,$id)
{
$category=Category::findOrFail($id);
dd($category);
return view('categorie.editcat', compact('category'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Category $category)
{
$category=Category::updated([
'nome'=>$request->nome,
]);
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function destroy(Category $category)
{
//
}
}
這是路線
Route::get('/categorie',[CategoryController::class,'index'])->name('categorie.categorie');
Route::get('/categorie/create',[CategoryController::class,'create'])->name('categorie.crea');
Route::post('/categorie/store',[CategoryController::class,'store'])->name('categorie.store');
Route::get('/categorie/store/{$id}',[CategoryController::class,'edit'])->name('categorie.edit');
Route::post('/categorie/update/{$id}',[CategoryController::class,'update'])->name('categorie.update');
這是帶有編輯形式的刀片
<x-layout>
<div class="container text-center">
<div class="row justify-content-center">
<div class="col-12 col-md-12 justify-content-center">
<h1>Categorie</h1>
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">NOME</th>
<th scope="col">STATO</th>
<th scope="col">AZIONI</th>
</tr>
</thead>
<tbody>
@foreach ($category as $cat)
<tr>
<th scope="row">{{$cat->id}}</th>
<th>{{$cat->nome}}</th>
<th>--</th>
<th><a href="{{route('categorie.crea')}}"><i class="fas fa-plus-circle"></i></a>
<form action="{{route('categorie.edit',$cat->id)}}" method="GET">
<button type="submit"><i hljs-string">"></i></button>
</form></th>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</x-layout>
任何解決方案?
uj5u.com熱心網友回復:
您必須將此 uri '/categorie/store/{$id}' 更改為'/categorie/store/{id}' 并在更新路由中執行此操作
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/372188.html
標籤:拉拉维尔
