I'm just getting started with Laravel and I'm using jetstream on a project for authentication.
I want to modify the login page and replace the email field with a select tag having the names of the registered users as options so that they will just have to choose their name in the list and enter their password to log in.
My problem is that I don't know how to make the data (from Users table) available when arriving on login page.
I've found the related route file vendor\laravel\fortify\routes\routes.php
and got the following code inside :
// Authentication...
if ($enableViews) {
Route::get('/login', [AuthenticatedSessionController::class, 'create'])
->middleware(['guest:'.config('fortify.guard')])
->name('login');
}
Then I found AuthenticatedSessionController.php
in vendor\laravel\fortify\src\Http\Controllers
in order to modify the create
function so that I could send the data through it, but here's actually the function :
public function create(Request $request): LoginViewResponse
{
return app(LoginViewResponse::class);
}
It doesn't return a view - in which case I think everything would have been fine - and I don't know how to handle this.
// vendor\laravel\fortify\src\Contracts\LoginViewResponse.php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface LoginViewResponse extends Responsable
{
//
}
In FortifyServiceProvider.php you can bind the data to the view like :
Fortify::loginView(function () {
$users = User::all();
return view('auth.login',compact('users'));
});