我正在练习 laravel ,关于 laracast 的基础课程 11th,想知道如果我从表单页面创建一个实体,
如下所示<html> blahblah..
..
<form method="post" action="{{ Route('customModel.store') }}">
forms.. many forms..
</form>
..
</html>
当我提交此表单时,数据将通过路由器流动。
Route::post('/customModel', [
'as'=>'customModel.store',
'uses'=>'CustomModelController@store
]);
自定义模型控制器有其名为store的方法,问题在这里。
public function store( Request $request )
{
$CustomModel = CustomModel::create([
'name' => Request('name'),
'desc' => Request('desc')
]);
// Here is the PROBLEMMMM..
return redirect('/field/'. $CustomModel->id );
}
感觉真的...毫米。。。直接使用重定向功能并直接附加一些变量来填充通配符值很奇怪。
还有其他方法可以替换redirect()
吗?
比如对Route
做某事?
您还可以使用route()
IlluminateRoutingRedirector
类的方法如下:
return redirect()->route('route_name', ['id' => $id]);