亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 Laravel 的列表中刪除待辦事項列表項?

如何從 Laravel 的列表中刪除待辦事項列表項?

PHP
幕布斯6054654 2021-08-27 09:27:01
我正在嘗試刪除 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.伙計們,如果你在其他地方看到過這個問題,我很抱歉,但我真的需要幫助,我沒有找到任何有用的東西。
查看完整描述

2 回答

?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

使用線


使用 App\Http\Controllers\Controller;


并用于刪除


在刀片


            <td>


                {!! Form::open(array('route' => array('products.destroy', $product->id), 'method' => 'delete')) !!}


                   <button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure?')"><i class="fa fa-trash-o"></i></button>


                   {!! Form::close() !!}

           </td>


查看完整回答
反對 回復 2021-08-27
?
青春有我

TA貢獻1784條經驗 獲得超8個贊

正如所寫的那樣,您有一個無效的資源豐富的路線Route::resource('', 'TodosController');,它應該可以解釋您的 404 錯誤。嘗試類似:

Route::resource('todo', 'TodosController')

然后使用 HTTP GET 重新測試 /todo 并查看您的TodosController@index()方法是否按預期工作。


查看完整回答
反對 回復 2021-08-27
  • 2 回答
  • 0 關注
  • 168 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號