php - 登录后更改重定向路径并使用 Laravel 8 使用 Google 登录
问题描述
我在目录 app/HTTP/controllers/LoginWithGoogle.php 中有这段代码
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Exception;
class LoginWithGoogleController extends Controller
{
public function redirectToGoogle()
{
return Socialite::driver('google')->redirect();
}
public function handleGoogleCallback()
{
try {
$user = Socialite::driver('google')->user();
$finduser = User::where('google_id', $user->id)->first();
if($finduser){
Auth::login($finduser);
return redirect()->intended('dashboard');
}else{
$newUser = User::create([
'name' => $user->name,
'email' => $user->email,
'google_id'=> $user->id,
'password' => encrypt('123456dummy')
]);
Auth::login($newUser);
return redirect()->intended('dashboard');
}
} catch (Exception $e) {
dd($e->getMessage());
}
}
}
我想更改return redirect()->intended('dashboard'); and return redirect()->intended('dashboard');
目录 resorces/views/index.blade.php 如果请帮助我该怎么办如果请帮助我,我是 Web 开发的新手。如果请帮助我,我该怎么做我是 Web 开发的新手。如果请帮助我,我该怎么做我是 Web 开发的新手。
解决方案
正如 Micheal 所说,您可以使用return redirect()->route('home')
而不是return redirect()->intended('dashboard');
为简单起见,您可以Route::view('/', 'index')->name('home');
在web.php中使用
此外,如果您想传递静态值,您可以在第三个参数中将其作为数组传递
Route::view('/', 'index', ['title' => 'Welcome to home'])->name('home');
推荐阅读
- python - Python 从列表或文本创建 md5 哈希
- python-3.x - 使用wfdb读取任意数据库的辅助信息
- arrays - 使用 New-AzureRmResourceGroupDeployment 时无法在 powershell 中检索 ARM 输出数组
- mysql - MySql从JPA以错误的顺序插入数据
- javascript - 代表调用函数抛出错误
- vue.js - Vuelidate 将数组传递给 not sameAs
- sql - 需要在下面的sql查询中返回空字符串行而不是空行
- node.js - 节点 js ejs 会话未正确关闭/打开
- c# - 在控制器中获取请求的 WebApi 版本
- flutter - Flutter AspNet Core SocketException (SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.1.87, port = 46186)