I'm working with laravel 5.4.
I try to make sell part (store) in my website and for items that I need to sell I don't want to use regular way!
what that means? usually in commerce websites when you set to order a product you will go to some place named cart and there has all calculations, you pay and it's done.
for me I try to get info with contact form, each item has a form inside and user fulfill the form then the data of user and product will be sent by email to admin so far everything is working but I also want to save these data that been sent by email in other table as Order_table
and show it to user in their panel that they've been requested to buy those item and if the items been paid or not yet.
Question: How to save these data in table include sum the price base on selected quantity by user?
this is my form that is in my items page:
<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>
this is the form validator and email sender:
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();
}
here are my routes for that form:
Route::get('/ask', 'ContactController@ask')->name('ask_product');
Route::post('/ask', 'ContactController@postask');