我正在尝试删除 Laravel 中的项目。这是我的代码:
这是我的路线:
Route::resource('', 'TodosController');
这是我的控制器:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Todo;
class TodosController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$todos = Todo::all();
return view('pages.home')->with('todos', $todos);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('pages.home');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'todo' => 'required'
]);
// Create todo
$todo = new Todo;
$todo->todo = $request->input('todo');
$todo->save();
return redirect('/')->with('success', 'Todo created');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$todo = Todo::find($id);
return view('pages.todo')->with('todo', $todo);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$todo = Todo::find($id);
return redirect('/')->with('success', 'Todo edited');
}
我希望它会删除该项目并重定向到/,但实际上它会重定向到/$id并抛出一个404 not found error.
伙计们,如果你在其他地方看到过这个问题,我很抱歉,但我真的需要帮助,我没有找到任何有用的东西。
拉丁的传说
青春有我