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 :: get users by role name - spatie/laravel-permission 
Php :: Parse error: syntax error, unexpected token "{" in C:xampphtdocsloginsystem1welcome.php on line 3 
Php :: php number multiple of 
Php :: laravel custom abort message 
Php :: get current user in symfony 
Php :: php photo upload 
Php :: Rename route resource in laravel 
Php :: sync laravel 
Php :: codeigniter select where 
Php :: how to change validation message in laravel 
Php :: how to access array using key in php 
Php :: catch warning php 
Php :: laravel migration text length 
Php :: macrotime phph 
Php :: append variable into string php 
Php :: Uncaught jquery-numerator requires jQuery to be loaded first wordpress 
Php :: swagger laravel 
Php :: php edit link 
Php :: php include file from another folder 
Php :: laravel get url parameter value in controller 
Php :: twig render string 
Php :: php pass 2 date value to javascript 
Php :: laravel find model inside the same model 
Php :: morph relation laravel 
Php :: You need to grant write permissions for PHP on the following directory: /var/www/html/prestashop 
Php :: map array php 
Php :: php mysqli date between 
Php :: php session destroy not working 
Php :: laravel disable logging 
Php :: how to enable autoreload on save laravel 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =