Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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 issue token

use IlluminateHttpRequest;

Route::post('/tokens/create', function (Request $request) {
    $token = $request->user()->createToken($request->token_name);

    return ['token' => $token->plainTextToken];
});
Comment

sanctum laravel github

php artisan vendor:publish --provider="LaravelSanctumSanctumServiceProvider"
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
Php :: laravel composer sanctum 
Php :: laravel check if environment is production 
Php :: Get data from array (from an API) in Laravel 
Php :: language_attributes for wordpress 
Php :: laravel eloquent relationship 
Php :: laravel unique id 
Php :: sms laravel 
Php :: laravel relation with limit 
Php :: codeigniter 3 image upload 
Php :: twig in array 
Php :: socket in laravel 
Php :: laravel admin multi images 
Php :: laravel migration char length 
Php :: namecheap shared cpanel change php version for subdomain 
Php :: php string variable 
Php :: magento 2 select to string 
Php :: php get function from different file 
Php :: wp wc php edit archive-product category page 
Php :: unique string faker laravel 
Php :: how to disable a button in a blade file 
Php :: woocommerce recipient email default change Function 
Php :: yii1 findall as array listData 
Php :: laravel self 
Php :: php date now 
Php :: html windows logo 
Php :: blade directive 
Php :: how to check page loading time in php 
Php :: php check if input is a positive integer 
Php :: convertir date php en français 
Php :: how to enable auto refresh on save 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =