Php Laravel 5:将参数后传给控制器
我想我想要的是非常基本的,我只是找不到正确的语法,因为我还在学习Laravel 所以,我使用谷歌验证在我的网站上登录。这需要对我的后端进行post请求,必须进行处理,我已将此逻辑放在控制器中。My routes.php:Php Laravel 5:将参数后传给控制器,php,laravel,Php,Laravel,我想我想要的是非常基本的,我只是找不到正确的语法,因为我还在学习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'
]);
我的控制器(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)]);
}