gpt4 book ai didi

controller - Laravel 5.2 从 Controller 返回 View

转载 作者:行者123 更新时间:2023-12-04 00:20:47 25 4
gpt4 key购买 nike

我在子目录“admin”中定义了一个 View ,它是一个编辑表单。提交后,将使用以下代码将其传递给 Controller ​​:

class ThisSiteController extends Controller
{
public function updateSite(Request $request)
{
$thissite = DB::table('this_site')->where('id',1)->get();
$thissite->headline = $request->headline;
$thissite->save();
return view('admin.editfront')->with('site', $thissite);
};
}

它正在更新一个标题,但我总是得到
NotFoundHttpException in RouteCollection.php line 161:

虽然调用编辑的路由是(并且工作正常):
Route::get('/admin/editfront', function() {
$thissite = DB::table('this_site')->where('id',1)->get();
return view('admin.editfront')->with('site', $thissite);
});

最佳答案

如果您正在提交表单,请确保路由使用的是 post。

Route::post('/admin/editfront', 'ThisSiteController@updateSite');

如果这不是问题,您能否显示您的表单代码和更新路线?

编辑
class ThisSiteController extends Controller
{
public function updateSite(Request $request)
{
DB::table('this_site')
->where('id',1)
->update(['headline' => $request->input('headline')]);
$thissite = DB::table('this_site')->where('id',1)->first();
return view('admin.editfront')->with('site', $site);
};
}

关于controller - Laravel 5.2 从 Controller 返回 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38941192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com