Search
 
SCRIPT & CODE EXAMPLE
 

PHP

install sanctum

composer require laravel/sanctum

php artisan vendor:publish --provider="LaravelSanctumSanctumServiceProvider"

php artisan migrate


"!!!!!!Next, if you plan to utilize Sanctum to authenticate an SPA, you should add Sanctum's middleware to your api middleware group within your application's app/Http/Kernel.php file:!!!!!"
'api' => [
    LaravelSanctumHttpMiddlewareEnsureFrontendRequestsAreStateful::class,
    'throttle:api',
    IlluminateRoutingMiddlewareSubstituteBindings::class,
],
Comment

laravel sanctum api

<?php
    public function login(Request $request)
    {
        if(Auth::attempt(['email' => $request->email, 'password' => $request->password])){ 
            $user = Auth::user(); 
            $success['token'] =  $user->createToken('MyApp')->plainTextToken; 
            $success['name'] =  $user->name;
   
            return $this->sendResponse($success, 'User login successfully.');
        } 
        else{ 
            return $this->sendError('Unauthorised.', ['error'=>'Unauthorised']);
        } 
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: Invalid credentials. symfony 
Php :: php get all days between two dates 
Php :: laravel migration table softdeletes 
Php :: ajax load more button wordpress 
Php :: what is Laravel Eloquent ORM. 
Php :: change php version on ubuntu 
Php :: php artisan serve stop 
Php :: laravel one to many relationship example 
Php :: download file using jquery php 
Php :: laravel migration change column order 
Php :: php to print value if key exists in array 
Php :: curl download progress bar php 
Php :: laravel migration int length 
Php :: quitar html con laravel 5 
Php :: convert to string php 
Php :: php foreach json object 
Php :: PHP sha1 — Calculate the sha1 hash of a string 
Php :: laravel auth sha-1 
Php :: laravel swagger 
Php :: how to remove third brackets from encoded json array in php 
Php :: wc php get acf fields product category 
Php :: laravel list all tbales 
Php :: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given 
Php :: heroku deploy php 
Php :: + php quantifer 
Php :: find auth laravel 
Php :: blade Keep input values after failed validation 
Php :: mssql php 
Php :: Token capabilities in vault 
Php :: drupal 8 $_GET 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =