Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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:将参数后传给控制器_Php_Laravel - Fatal编程技术网

Php Laravel 5:将参数后传给控制器

Php Laravel 5:将参数后传给控制器,php,laravel,Php,Laravel,我想我想要的是非常基本的,我只是找不到正确的语法,因为我还在学习Laravel 所以,我使用谷歌验证在我的网站上登录。这需要对我的后端进行post请求,必须进行处理,我已将此逻辑放在控制器中。My routes.php: Route::post('google' , [ 'as' => 'verify.index', 'uses' => 'verify@verifyIdToken' ]); 我的控制器(verify.php): 作为补充参考,我的实际post请求如

我想我想要的是非常基本的,我只是找不到正确的语法,因为我还在学习Laravel

所以,我使用谷歌验证在我的网站上登录。这需要对我的后端进行post请求,必须进行处理,我已将此逻辑放在控制器中。My routes.php:

Route::post('google' ,  [
    'as' => 'verify.index',
    'uses' => 'verify@verifyIdToken'
]);
我的控制器(verify.php):

作为补充参考,我的实际post请求如下所示:

Route::post('google' ,  [
        'as' => 'verify.index',
        'uses' => 'verify@verifyIdToken ~with $_POST['id'] as $token'
    ]);
$.post(“http://example.com/google“,{email:profile.getEmail(),id:id_token})

控制器方法:

public function verifyIdToken(Request $request)
{
    // Not necessary but a better practice for ajax 'POST' responses.

    if($request->ajax() &&  $request->isMethod('post'))
    {
        return $request::get('token');
    }
}
路线:

Route::post('google', ['as' => 'some.alias', 'uses' => 'SomeController@verifyIdToken']);

您正在寻找Laravel的
请求
类。您应该在方法上键入hint类,然后允许加载选项来实际获取数据。比如:

use Illuminate\Http\Request;

public function verifyIdToken(Request $request)
{
    $token = $request->input('id');
    $email = $request->input('email');
    return $this->getAuth()->verifyIdToken($token);
    echo $this->getAuth()->verifyIdToken($token);
    return view('aviewII')->with(['verify' => json_encode(verifyIdToken($token)),'email'=> json_encode($email)]);
}
这本书有很多有用的信息

use Illuminate\Http\Request;

public function verifyIdToken(Request $request)
{
    $token = $request->input('id');
    $email = $request->input('email');
    return $this->getAuth()->verifyIdToken($token);
    echo $this->getAuth()->verifyIdToken($token);
    return view('aviewII')->with(['verify' => json_encode(verifyIdToken($token)),'email'=> json_encode($email)]);
}