php - Laravel - HTML POST 表单,找不到页面

标签 php html mysql laravel

我目前正在使用 Laravel 制作这个 Web 应用程序,您可以使用 HTML 表单将新产品添加到 MySQL。

问题是,当我按“添加产品”时,它不起作用,它向我显示:

https://i.gyazo.com/4c34432ff69857809476f78aea5c6582.png

HTML 表单

<form action="store" method="POST">

                    <div class="form-group">
                        {{ Form::label('product_name', null, ['class' => 'control-label']) }}
                        {{ Form::text('product_name', null, ['class' => 'form-control']) }}
                        <br>
                    </div>
                    <div class="form-group">
                        {{ Form::label('product_description', null, ['class' => 'control-label']) }}
                        {{ Form::text('product_description', null, ['class' => 'form-control']) }}
                        <br>
                    </div>
                    <div class="form-group">
                        {{ Form::label('product_producer', null, ['class' => 'control-label']) }}
                        <select name="producator" class="form-control">
                            <option>Pick producer...</option>
                            @if(isset($marks))
                                @foreach($marks as $m)
                                    <option value="{{$m->producer_ID}}">{{$m->producer_name}}</option>
                                @endforeach
                            @endif
                        </select>
                        <br>
                    </div>
                    <button type="submit" class="btn btn-info">Add product</button>
                </form>

web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    //return view('welcome');
    $products = DB::table('laravel_products')->select('product_name', 'product_about', 'producer_name', 'product_added')->get();
    $marks = DB::table('laravel_producers')->select('producer_ID', 'producer_name')->get();
    return view(
        'welcome', 
        compact('products'), 
        compact('marks')
    );
});

Route::get("index", "test@index");
Route::post("store", "test@store");

/*
Route::post('profile', 
    [
        'before' => 'csrf',
        function()
        {

        }
    ]
);*/

test.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\laravel;

class test extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view("welcome");
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $user = new Laravel;
        $user->product_name = Input::get("product_name");
        $user->product_description = Input::get("product_description");
        $user->product_producer = Input::get("product_producer");
        $user->save();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

数据库表如下所示: https://i.gyazo.com/a83407718f756df02effd8461547d223.png

当我按下“添加产品”时,我必须做什么才能将字段中的值插入到我的数据库中?

提前谢谢您!

最佳答案

当您提交表单时,您的数据是否存储到数据库中?。如果它将数据存储到数据库中,那么您需要在存储数据后加载 View ,正如我在将数据存储到数据库后看到的那样,您没有加载 View ,因为它显示找不到您的页面。谢谢

关于php - Laravel - HTML POST 表单,找不到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45629519/

相关文章:

php - 如何检查变量是否包含日期或日期和文本?

php - 检查模型以查看 Yii-PHP 中是否存在记录

php - 对 mysql 的搜索结果进行排序

html - 手机版不显示图片

php - 从 5 列表 MySQL 中选择 2-3 个数字组合

php - mysql 和 php 不支持阿拉伯语

javascript - LocalStorage追加新元素

javascript - Li click 无法与 select2 插件一起使用

sql - MySQL foreach?

mysql - SQL 获取当前日期和特定时间