Skip to content

Full Stack Programmer

Just another blog classic, isn't it!

Full Stack Programmer

Just another blog classic, isn't it!

  • Blog
  • Who am i?
  • More About Me
    • Skills
    • Experience
    • Recommendations
    • Education
    • My Activities
  • IT Services
  • Gaming
  • Contact
  • Privacy & Policy
Laravel

Laravel: Login with email or phone

 Danyal  March 18, 2021  Posted in Code snippets, Laravel, PHP, Programming Tagged Authentication, LaravelPassport, login
public function login(Request $request)
{
    $user = User::where('email', $request->emailOrPhone)
                    ->orWhere('phone', $request->emailOrPhone)
                    ->first();
    if($user){
        if (Hash::check($request->password, $user->password)) {

            $tokenResult = $user->createToken('Personal Access Token');
            $token = $tokenResult->token;
            if ($request->remember_me)
                $token->expires_at = Carbon::now()->addWeeks(1);
            $token->save();
            return response()->json([
                'access_token' => $tokenResult->accessToken,
                'expires_at' => Carbon::parse(
                    $tokenResult->token->expires_at
                )->toDateTimeString()
            ]);

        } else {
            $response = ['Password incorrect'];
            return response($response, 422);
        }
    }else {
        $response = ['User does not exist'];
        return response($response, 422);
    }

}
Post Views: 4,462
Author: Danyal
I'm a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.

Post navigation

Build issue with Xcode 12.3 – file not found #include “ruby/config.h” →
← Drupal: How to enable HTTPS support in Drupal

View: LINKEDIN

Posts

  • Screen Size in React Native: Two Approaches November 5, 2025
  • Loading Custom Fonts in a React Native App (with Expo) November 2, 2025
  • Cascading Styles in React Native November 2, 2025
  • SafeAreaView Deprecation in React Native: What You Need to Know October 30, 2025
  • Behind the Scenes of JWTAuth::attempt() in Laravel September 28, 2025

Tags

array (3) Authentication (8) build (3) coding (8) commands (6) components (3) composer (4) database (5) devops (5) docker (3) drupal (5) Eloquent (3) error (5) Git (3) help (3) ios (5) javascript (19) jQuery (3) js (5) laravel (24) Laravel 5.6 (6) laravel5.7 (4) LaravelPassport (3) linux (7) lumen (7) LumenPassport (3) migration (4) mysql (8) network (3) node (3) php (27) python (6) security (4) solution (3) ssh (3) SSL (3) technology (8) tip of the day (3) tips (7) token (3) ubuntu (8) upgrade (3) vue.js (3) vuejs (13) vuex (3)

Advertisement

Advertisement

Categories

  • Apache2 (1)
  • Chrome (1)
  • CI/CD (1)
  • CkEditor (1)
  • Cloud (2)
  • CMS (8)
  • Code Editors (1)
  • Code snippets (1)
  • Composer (1)
  • Daily Tips (6)
  • Databases (5)
  • Development (5)
  • Docker (4)
  • Eloquent (1)
  • EU (1)
  • File System (1)
  • Git (3)
  • Google (2)
  • GraphQL (2)
  • Gulp (1)
  • Heandy Tips (2)
  • HTML (1)
  • javascript (22)
  • JWTAuth (1)
  • Laravel (33)
  • Laravel 5.5 (8)
  • Linux (10)
  • Lumen (6)
  • Microbit (4)
  • MySQL (5)
  • News & Updates (5)
  • Nginx (2)
  • Node (1)
  • Nuxt.js (3)
  • osMac (3)
  • Package Managers (1)
  • PHP (30)
  • Programming (9)
  • Python (3)
  • ReactNative (4)
  • Ruby on Rails (1)
  • Support (1)
  • Symfony (3)
  • Tips (7)
  • Tools (1)
  • Ubuntu (11)
  • Ubuntu 16.04 (10)
  • Ubuntu 17 (6)
  • Uncategorized (8)
  • Vlog (1)
  • Vuejs (11)
  • Wordpress (1)
  • xcode (3)

Recent Posts

  • Screen Size in React Native: Two Approaches
  • Loading Custom Fonts in a React Native App (with Expo)
  • Cascading Styles in React Native
  • SafeAreaView Deprecation in React Native: What You Need to Know

Tags

array (3) Authentication (8) build (3) coding (8) commands (6) components (3) composer (4) database (5) devops (5) docker (3) drupal (5) Eloquent (3) error (5) Git (3) help (3) ios (5) javascript (19) jQuery (3) js (5) laravel (24) Laravel 5.6 (6) laravel5.7 (4) LaravelPassport (3) linux (7) lumen (7) LumenPassport (3) migration (4) mysql (8) network (3) node (3) php (27) python (6) security (4) solution (3) ssh (3) SSL (3) technology (8) tip of the day (3) tips (7) token (3) ubuntu (8) upgrade (3) vue.js (3) vuejs (13) vuex (3)

RSS Rida.dk

  • The Berlin Wall
  • Turkey: one of top 10 most visited countries #6
  • Italy: one of top 10 most visited countries #5
  • Daily Motivation #3
  • Daily Motivation #2
  • Daily Motivation #1
  • China: one of top 10 most visited countries #4
  • USA: one of top 10 most visited countries #3
  • Spain: one of top 10 most visited countries #2
  • France: one of top 10 most visited countries #1

RSS Abdulraheem.dk

  • Facts about Lotte world tower
  • Facts About Ping An Finance Tower
  • Facts about Abraj Al-Bait
  • Facts about Shanghai tower
  • Facts about Merdeka 118
  • Facts about Brandenburg gate
  • Facts about the Berliner Fernsehturm
  • Top ten tallest buildings in the world
  • Facts about Lego House Billund
  • Facts about Universe science park

RSS Laravel News

  • Laravel Cloud Adds “Markdown for Agents” to Serve AI-Friendly Content
  • Generate Secure, Memorable Passphrases in PHP with PHP Passphrase
  • Laravel Releases Nightwatch MCP Server for Claude Code and AI Agents
  • Single Table Inheritance for Eloquent Models Using Parental
  • Laravel Live Denmark Returns to Copenhagen in August 2026

RSS Unknown Feed

RSS Abdulsamad.dk

  • Jake and the Panic Room
  • Brunlig lugtende morgenkaffe
  • DEn forvundene hund
  • Mysteriet i parken
  • Hvad er Burj Khalifa
  • Dødt liv
  • slæbende blod
  • Den udødlig væsen
  • Kælderen
  • Den arabiske spiderman

We runs on green energy!

This website is hosted Green - checked by thegreenwebfoundation.org

Copyright © 2026 Full Stack Programmer

Design by ThemesDNA.com

Verified by ExactMetrics