PHP code example of whyounes / laravel-passwordless-auth
1. Go to this page and download the library: Download whyounes/laravel-passwordless-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
whyounes / laravel-passwordless-auth example snippets
// routes/web.php
Route::post('/login/direct', function(Request $request){
// send link to user mail
$user = App\User::where('email', $request->get('email'))->first();
if (!$user) {
return redirect()->back(404)->with('error', 'User not found');
}
// generate token and save it
$token = $user->generateToken(true);
// send email to user
\Mail::send("mails.login", ['token' => $token], function($message)use($token){
$message->to($token->user->email);
});
});
// routes/web.php
Route::get('/login/{token}', function(Request $request, $token){
$user = App\User::where('email', $request->get('email'))->first();
if (!$user) {
dd('User not found');
}
if($user->isValidToken($token))
{
// Login user
Auth::login($user);
} else {
dd("Invalid token");
}
});