Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel的数据库中保存联系人表单的信息_Php_Mysql_Forms_Laravel - Fatal编程技术网

Php 在laravel的数据库中保存联系人表单的信息

Php 在laravel的数据库中保存联系人表单的信息,php,mysql,forms,laravel,Php,Mysql,Forms,Laravel,我和拉威尔5.4一起工作 我试着在我的网站上销售部分(商店),对于我需要销售的物品,我不想用常规的方式 这意味着什么?通常在商业网站上,当你准备订购一种产品时,你会去一个叫购物车的地方,那里有所有的计算,你付钱,就完成了 对我来说,我试着通过联系方式获取信息,每个项目都有一个表单,用户填写表单,然后用户和产品的数据将通过电子邮件发送给管理员,目前一切正常,但我还想将通过电子邮件发送的这些数据保存在其他表格中,作为Order_table,并在他们的面板中向用户显示他们已被要求购买这些项目,以及这些

我和拉威尔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>
以下是我的表格路线:

    Route::get('/ask', 'ContactController@ask')->name('ask_product');  

Route::post('/ask', 'ContactController@postask');

验证后,您可以编写代码将数据存储到表中

DB::table('Order_table')->insert(
    ['username' => $request->username,
    'email' => $request->email,
    'product' => $request->product,
    'note' => $request->note,
    'quantity' => $request->quantity]
);

如果您使用ORM,它将/可能看起来像:(取决于您的laravel设置)

使用:


您可以接收所有输入表单,而无需单独传递表单,并将其保存到订单表。

为什么在表单方法为
POST
的情况下使用route with
get
?检查表单中以及路由文件中的路由操作。然后对价格求和如何?我该如何告诉您将其保存在哪个表中?Orders链接到表'Orders'。这就是ORM的工作原理。你可以即时算出总价。因此,当向用户查看时。比如:echo$订单->数量*$产品->价格;(例如)@RobertNicjoo您可以在这里阅读ORM的工作原理。拉雷维尔雄辩的模型。
DB::table('Order_table')->insert(
    ['username' => $request->username,
    'email' => $request->email,
    'product' => $request->product,
    'note' => $request->note,
    'quantity' => $request->quantity]
);
$order = Orders::create($request->all());
$order = Orders::create($request->all());