【发布时间】:2018-01-13 05:01:48
【问题描述】:
我正在练习 laravel ,关于 laracast 的第 11 课基础课,想知道我是否从下面的表单页面创建实体
<html> blahblah..
..
<form method="post" action="{{ Route('customModel.store') }}">
forms.. many forms..
</form>
..
</html>
当我提交此表单时,数据将通过路由器。
Route::post('/customModel', [
'as'=>'customModel.store',
'uses'=>'CustomModelController@store
]);
CustomModelController 有一个名为 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函数,直接附加一些变量来填充通配符值。
还有其他方法可以代替redirect()吗?
像Route 或其他人一样做某事?
【问题讨论】:
-
是你不喜欢的辅助函数还是连接通配符值?
-
你可以做
return app()->make("ControllerYouWant")->methodYouWant($CustomModel->id),但仅仅因为你可以并不意味着你应该 -
m.. 我认为连接值是我不喜欢的.. 因为感觉就像,存在一种更好更简单的方法来做到这一点。它存在吗?