Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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 我想在提交注册表单时将数据从URI传递到注册控制器_Php_Laravel - Fatal编程技术网

Php 我想在提交注册表单时将数据从URI传递到注册控制器

Php 我想在提交注册表单时将数据从URI传递到注册控制器,php,laravel,Php,Laravel,我加载注册页面的路径是 Route::get('join/{mobileNumber}', 'JoinController@index'); 提交表单时是否有方法传递变量“mobileNumber”? 我可以在表单中创建隐藏输入,但这是进一步传递变量的最佳方式吗?是,将变量从索引方法传递到视图: routes.php 联合控制器 mobile_join.blade.php {!!csrf_field()!!} HTTP 1.1支持两种方法,GET和POST,我们通过POST发送表单数据,并

我加载注册页面的路径是

Route::get('join/{mobileNumber}', 'JoinController@index');
提交表单时是否有方法传递变量“mobileNumber”?
我可以在表单中创建隐藏输入,但这是进一步传递变量的最佳方式吗?

是,将变量从索引方法传递到视图:

routes.php 联合控制器 mobile_join.blade.php

{!!csrf_field()!!}

HTTP 1.1支持两种方法,GET和POST,我们通过POST发送表单数据,并通过GET传递mobileNumber。Laravel使用正则表达式从URL提取字符串并设置变量。

是,将变量从索引方法传递到视图:

routes.php 联合控制器 mobile_join.blade.php

{!!csrf_field()!!}

HTTP 1.1支持两种方法,GET和POST,我们通过POST发送表单数据,并通过GET传递mobileNumber。Laravel使用正则表达式从URL中提取字符串并设置变量。

如果在表单中填写了值,则应在表单上使用POST方法。问题是,在填写表单后,我需要进一步传递变量“mobileNumber”,而此变量不是表单的一部分。然后应使用会话。我不确定laravel是否具有此功能,但一些PHP框架提供了一个flash会话,该会话的生命周期将在下一个请求中到期。您可以通过“触摸”它使其变长。如果值填充在表单中,则应在表单上使用POST方法。问题是,在填充表单后,我需要进一步传递变量“mobileNumber”,而此变量不是表单的一部分。然后您应使用会话。我不确定laravel是否具有此功能,但一些PHP框架提供了一个flash会话,该会话的生命周期将在下一个请求中到期。您可以通过“触摸”它使其变长。我的JoinController中的postJoin函数中有一个RegisterRequest变量:
公共函数postJoin(RegisterRequest$request)
公共函数postJoin($mobileNumber,RegisterRequest$request)
不起作用。如果键入
dd($mobileNumber)
在postJoin方法中,会发生什么?会显示mobileNumber变量。好的,现在我必须向请求对象添加额外的变量。正在尝试搜索它。很可能会这样做。是否要验证RegiterRequest中的mobileNumber?我的JoinController中的postJoin函数中有一个RegisterRequest变量:
公共函数postJoin(RegisterRequest$request)
公共函数postJoin($mobileNumber,RegisterRequest$request)
不工作。如果键入
dd($mobileNumber)
在postJoin方法中,会发生什么?会显示mobileNumber变量。好的,现在我必须向请求对象添加额外的变量。正在尝试搜索它。很可能会完成。是否要在RegiterRequest中验证mobileNumber?
Route::get('join/{mobileNumber}', 'JoinController@getJoin');
Route::post('join/{mobileNumber}', 'JoinController@postJoin');
<?php

# ...

    public function getJoin($mobileNumber)
    {
        # ...
        return view('mobile_join', compact('mobileNumber'));
    }

    public function postJoin($mobileNumber, RegisterRequest $request)
    {
        $user = new User();
        $username = $request->input('username');
        $user->password = bcrypt($request->input('password'));
        $user->email = $request->input('email');
        $user->phone = $mobilePhone;
        $user->is_active = 0;
        $user->save();

        # or

        $data = $request->only(['username', 'email']);
        $data['phone'] = $mobilePhone;
        $data['password'] = bcrypt($data['password']);
        $data['is_active'] = 0;

        $user = User::create($data);

        # ...

        redirect()->route('...');
    }
protected $fillable = ['username', 'email', 'phone', 'password', 'is_active'];
<form action="/join/{{ $mobileNumber }}" method="post">
    {!! csrf_field() !!}
    <!-- ... -->
</form>