Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

laravel sanctum

//install
composer require laravel/sanctum
  
// vendor
php artisan vendor:publish --provider="LaravelSanctumSanctumServiceProvider"
Comment

laravel sanctum

Broadcast::routes(['middleware' => ['auth:sanctum']]);
Comment

sanctum laravel

composer require laravel/sanctum
Comment

laravel sanctum

return $user->createToken('token-name', ['server:update'])->plainTextToken;
Comment

laravel sanctum

use AppModelsSanctumPersonalAccessToken;
use LaravelSanctumSanctum;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
}
Comment

laravel sanctum

use IlluminateHttpRequest;

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});
Comment

laravel sanctum

axios.defaults.withCredentials = true;
Comment

laravel sanctum

use LaravelSanctumHasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
}
Comment

laravel sanctum

// Revoke all tokens...
$user->tokens()->delete();

// Revoke the token that was used to authenticate the current request...
$request->user()->currentAccessToken()->delete();

// Revoke a specific token...
$user->tokens()->where('id', $tokenId)->delete();
Comment

laravel sanctum

if ($user->tokenCan('server:update')) {
    //
}
Comment

laravel sanctum

axios.get('/sanctum/csrf-cookie').then(response => {
    // Login...
});
Comment

laravel sanctum

use LaravelSanctumPersonalAccessToken as SanctumPersonalAccessToken;

class PersonalAccessToken extends SanctumPersonalAccessToken
{
    // ...
}
Comment

laravel sanctum

foreach ($user->tokens as $token) {
    //
}
Comment

laravel sanctum

return $request->user()->id === $server->user_id &&
       $request->user()->tokenCan('server:update')
Comment

laravel sanctum

'domain' => '.domain.com',
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
Shell :: yum check package version 
Shell :: Can we install XAMPP on Linux from a given link 
Shell :: install nixos mac m1 
Shell :: how to install python using windows command prompt 
Shell :: install tesseract-ocr jpn 
Shell :: permission terminal ubuntu 
Shell :: how to ssh copy to my aws ec2 linux 
Shell :: cmd move overwrite file 
Shell :: add ssh public key to server 
Shell :: what is the use of bashrc file in linux 
Shell :: pyinquier install 
Shell :: reset branch to other branch 
Shell :: import bjson mongodb 
Shell :: find command path 
Shell :: what is regedit in windows 
Shell :: undo commit after push 
Shell :: find hidden directories and files from a website wfuzz 
Shell :: winui 3 installation 
Shell :: install docker in suse linux 
Shell :: docker no space left on device ubuntu but only 75% use? 
Shell :: how to register nuget repository powershell 
Shell :: apk remove package 
Shell :: git push branch 
Shell :: locate file in KALI Linux 
Shell :: openstack show ports 
Shell :: backup ubuntu 22 
Shell :: grep pattern options 
Shell :: install jenkins 
Shell :: how to compress files in powershell 
Shell :: how to make migrations in models in django 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =