将参数传递给 jetsream 项目中的登录视图
Pass parameters to the login view in a jetsream project
我刚刚开始使用 Laravel,我在一个项目上使用 jetstream 进行身份验证。
我想修改登录页面并用select标签替换电子邮件字段,其中注册用户的名字作为选项,这样他们就只需要在列表并输入他们的密码以登录。
我的问题是我不知道如何使数据(来自用户table)在到达登录页面时可用。
我找到了相关的路由文件vendor\laravel\fortify\routes\routes.php
,里面有如下代码:
// Authentication...
if ($enableViews) {
Route::get('/login', [AuthenticatedSessionController::class, 'create'])
->middleware(['guest:'.config('fortify.guard')])
->name('login');
}
然后我在vendor\laravel\fortify\src\Http\Controllers
中找到了AuthenticatedSessionController.php
来修改create
函数,这样我就可以通过它发送数据,但实际上是函数:
public function create(Request $request): LoginViewResponse
{
return app(LoginViewResponse::class);
}
它没有 return 视图 - 在这种情况下我认为一切都会很好 - 我不知道如何处理这个。
// vendor\laravel\fortify\src\Contracts\LoginViewResponse.php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface LoginViewResponse extends Responsable
{
//
}
在 FortifyServiceProvider.php 中,您可以像这样将数据绑定到视图:
Fortify::loginView(function () {
$users = User::all();
return view('auth.login',compact('users'));
});
我刚刚开始使用 Laravel,我在一个项目上使用 jetstream 进行身份验证。
我想修改登录页面并用select标签替换电子邮件字段,其中注册用户的名字作为选项,这样他们就只需要在列表并输入他们的密码以登录。
我的问题是我不知道如何使数据(来自用户table)在到达登录页面时可用。
我找到了相关的路由文件vendor\laravel\fortify\routes\routes.php
,里面有如下代码:
// Authentication...
if ($enableViews) {
Route::get('/login', [AuthenticatedSessionController::class, 'create'])
->middleware(['guest:'.config('fortify.guard')])
->name('login');
}
然后我在vendor\laravel\fortify\src\Http\Controllers
中找到了AuthenticatedSessionController.php
来修改create
函数,这样我就可以通过它发送数据,但实际上是函数:
public function create(Request $request): LoginViewResponse
{
return app(LoginViewResponse::class);
}
它没有 return 视图 - 在这种情况下我认为一切都会很好 - 我不知道如何处理这个。
// vendor\laravel\fortify\src\Contracts\LoginViewResponse.php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface LoginViewResponse extends Responsable
{
//
}
在 FortifyServiceProvider.php 中,您可以像这样将数据绑定到视图:
Fortify::loginView(function () {
$users = User::all();
return view('auth.login',compact('users'));
});