我正在使用laravel 5.4。
我尝试在我的网站上制作销售部分(商店)以及我需要销售的商品我不想使用常规方式!
这意味着什么?通常在商业网站上,当您设置订购产品时,您将前往某个名为购物车的地方,并且有所有计算,您付款并完成。对我来说,我尝试通过联系表单获取信息,每个项目都有一个表格,用户填写表格然后用户和产品的数据将通过电子邮件发送给管理员到目前为止一切正常但我也想保存这些数据已通过电子邮件发送到其他表中Order_table
,并在其面板中向用户显示他们已被要求购买这些商品以及商品是否已付款。
问题: 如何在表格中保存这些数据包括按用户对所选数量的价格总和?
这是我的项目页面中的表单:
<form class="form-horizontal" action="{{route('ask_product')}}" method="POST" id="contact_form">
{{ csrf_field() }}
<div class="form-group">
<label class="col-md-3 control-label">UserName</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input name="username" value="{{ Auth::user()->username }}" class="form-control" type="text" readonly>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-3 control-label">E-Mail</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input name="email" value="{{ Auth::user()->email }}" class="form-control" type="text" readonly>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-product-hunt"></i></span>
<input name="product" value="{{ $product->title }}" class="form-control" type="text" readonly>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="type">Quantity</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-file-code-o"></i></span>
<select class="form-control" id="type" name="quantity">
<option value="">Select Quantity</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="More than 5">More than 5</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Note to seller</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-commenting-o"></i></span>
<textarea name="note" id="text" placeholder="Your note to seller here..." class="form-control" rows="8" ></textarea>
</div>
<h6 class="pull-right" id="count_message"></h6>
</div>
</div>
<div class="text-center">
<input type="submit" class="btn btn-block btn-success" value="Send">
</div>
</form>
这是表单验证器和电子邮件发件人:
public function ask() {
return view('frontend.shopsingle');
}
public function postask(Request $request) {
$this->validate($request, array(
'username' => 'required',
'email' => 'required|email',
'product' => 'required',
'note' => 'required|min:10|max:500',
'quantity' => 'required',
));
$data = array(
'username' => $request->username,
'email' => $request->email,
'product' => $request->product,
'note' => $request->note,
'quantity' => $request->quantity,
);
Mail::send('emails.ask', $data, function($message) use ($data) {
$message->from($data['email']);
$message->to('robertnicjoo@outlook.com');
$message->subject($data['product']);
});
Session::flash('flash_message', 'Your Order was sent. Our sell team will contact you shortly.');
return redirect()->back();
}
以下是该表格的路线:
Route::get('/ask', 'ContactController@ask')->name('ask_product');
Route::post('/ask', 'ContactController@postask');
答案 0 :(得分:0)
验证后,您可以编写代码将数据存储到表
中DB::table('Order_table')->insert(
['username' => $request->username,
'email' => $request->email,
'product' => $request->product,
'note' => $request->note,
'quantity' => $request->quantity]
);
答案 1 :(得分:0)
如果您使用ORM,它会/看起来很简单:(取决于您的laravel设置)
$order = Orders::create($request->all());
答案 2 :(得分:0)
$ order = Orders :: create($ request-&gt; all()); 您可以接收所有输入表单而不将其单独传递并将其保存到订单表