从路线/网址获取型号ID [英] Get model id from route/url
问题描述
我有一个用户,事件和报价模型.用户可以进行活动 然后其他用户可以为该活动提供报价.但是现在我不知道如何在offer的存储方法中获取事件ID
I have a user, event and offer model. A user can make an event and then another user can make an offer for that event. But now I don't know how to get event id in store method for offer
我收到错误event_id not defined
.
当我单击要约时,该事件的显示视图打开,并且该视图中有事件模型...并且在该视图上,有一个表单可以提交要约,但我不知道该如何获得该事件ID
When i click on make offer the show view opens for that event and i have the event model in that view...and on that view there is a form to submit offer and i don't know how to get that event id
当我这样做dd($request->all());
时,只有该形式的变量
when i do dd($request->all());
there are only variables from that form
我需要的是该事件的ID.
and what i need is the id of that event.
推荐答案
使用store()
方法,您需要向表单添加隐藏的输入,例如:
With store()
method you need to add hidden input to the form, for example:
{!! Form::hidden('event_id', $event->id) !!}
然后获取数据:
$event_id = $request->event_id;
这篇关于从路线/网址获取型号ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!