Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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/6/multithreading/4.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 5.6,进行多页注册,并将输入数据保存到会话_Php_Jquery_Mysql_Ajax_Laravel - Fatal编程技术网

Php Laravel 5.6,进行多页注册,并将输入数据保存到会话

Php Laravel 5.6,进行多页注册,并将输入数据保存到会话,php,jquery,mysql,ajax,laravel,Php,Jquery,Mysql,Ajax,Laravel,我想有人给我一些建议。我真的卡住了。我是新来的。我会尝试将注册页设置为多页。我想这样做: 第一个页面用户输入一些数据,然后单击next,数据将存储到会话并重定向到第二个页面注册 之后,用户输入一些数据,当用户单击finish时,数据将保存到表用户 我使用laravel身份验证php artisan make:auth并根据需要修改视图和控制器。但当我点击下一步按钮时,什么也没发生 当我检查控制台时,它显示POSThttp://localhost:8000/registrasi/v2 500(内部

我想有人给我一些建议。我真的卡住了。我是新来的。我会尝试将注册页设置为多页。我想这样做:

  • 第一个页面用户输入一些数据,然后单击next,数据将存储到会话并重定向到第二个页面注册
  • 之后,用户输入一些数据,当用户单击finish时,数据将保存到表用户
  • 我使用laravel身份验证
    php artisan make:auth
    并根据需要修改视图和控制器。但当我点击下一步按钮时,什么也没发生

    当我检查控制台时,它显示
    POSThttp://localhost:8000/registrasi/v2 500(内部服务器错误)

    当我登录网络标签时,上面写着

    "{,…}
    exception
    :
    "Illuminate\Database\QueryException"
    file
    :
    "C:\xampp\htdocs\vojo\vendor\laravel\framework\src\Illuminate\Database\Connection.php"
    line
    :
    664
    message
    :
    "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'senderEmail' in 'where clause' (SQL: select count(*) as aggregate from `users` where `senderEmail` = clubband@gmail.com)"
    trace
    :
    [{file: "C:\xampp\htdocs\vojo\vendor\laravel\framework\src\Illuminate\Database\Connection.php",…},…]"
    
    这是我的密码

    Web.php

    Route::get('/', function () {
    return view('welcome');
    });
    
    Auth::routes();
    Route::get('/home', 'HomeController@index')->name('home');
    Route::group(['prefix'=>'registrasi'], function(){
    Route::get('/v1','Auth\RegisterController@ShowView');
    Route::post('/v2','Auth\RegisterController@store');
    }); 
    
    我的迁移用户表

        <?php
    
       use Illuminate\Support\Facades\Schema;
       use Illuminate\Database\Schema\Blueprint;
       use Illuminate\Database\Migrations\Migration;
    
       class CreateUsersTable extends Migration
       {
       /**
        * Run the migrations.
        *
        * @return void
        */
        public function up()
        {
           Schema::create('users', function (Blueprint $table) {
                $table->increments('id');
                $table->string('username')->unique();
                $table->string('password');
                $table->string('email')->unique();
                $table->string('name');
                $table->enum('user_type', ['customer', 'band', 'admin'])- 
                >default('customer');
                $table->string('profile_picture')->nullable();
                $table->datetime('last_login')->nullable();
                $table->rememberToken();
                $table->timestamps();
                });
         }
    
         /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('users');
         }
    }
    

    对于如图所示的错误消息,您有一个SQL错误,这意味着您向不存在的表发送了一个字段“senderEmail”:

    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'senderEmail' in 'where clause' (SQL: select count(*) as aggregate from users where senderEmail = clubband@gmail.com)
    
    其次,要在会话中存储数据,请使用:

    Session::put('key',$value);
    
    Session::get('key')
    
    要从会话中获取数据,请使用:

    Session::put('key',$value);
    
    Session::get('key')
    
    不要忘记添加一个使用行,例如:

    use Session;
    

    您需要在store()方法中进行适当的验证。您需要在唯一验证中指定列名,否则它将只接受请求名作为列名

    这是修改后的代码

    protected function store(Request $request){
        $this->validate($request, [
            'senderName' => 'required|string|max:255',
            'senderEmail' => 'required|string|email|max:255|unique:users,email',
            'senderUsername' => 'required|string|max:255|unique:users,username',
            'senderPassword' => 'required|string|min:6'
        ]);
    
        Session::put('SimpanRegisterBand',$request->all());
    
        return view('layouts.test');
    }
    

    谢谢你的建议,先生。但我想先将数据存储到会话中,然后再将数据存储到数据库中。对我的代码有什么建议我应该更改吗,先生?您应该有两个视图,这意味着两个操作,因此在第一个操作中,$request->all()进入会话并重定向到第二个页面(视图),然后转到第二个操作(它可以是控制器中的存储操作)在这里,您可以将传入数据存储到会话中,获取新旧数据并将它们存储到数据库中