dpfl37651 2017-07-22 06:09
浏览 68
已采纳

在laravel中保存数据库中的联系表格信息

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');
  • 写回答

3条回答 默认 最新

  • douyin2962 2017-07-22 06:21
    关注

    after validation you can write the code to store the data into table

    DB::table('Order_table')->insert(
        ['username' => $request->username,
        'email' => $request->email,
        'product' => $request->product,
        'note' => $request->note,
        'quantity' => $request->quantity]
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?