laravel sanctum
//install
composer require laravel/sanctum
// vendor
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
laravel sanctum
//install
composer require laravel/sanctum
// vendor
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
laravel sanctum
composer create-project --prefer-dist laravel/laravel appname
composer require laravel/sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
composer require laravel/jetstream
php artisan jetstream:install inertia
php artisan migrate
npm install
php artisan vendor:publish --tag=jetstream-views
php artisan serve
npm run hot
laravel sanctum
return $user->createToken('token-name', ['server:update'])->plainTextToken;
laravel sanctum
use Illuminate\Http\Request;
Route::post('/tokens/create', function (Request $request) {
$token = $request->user()->createToken($request->token_name);
return ['token' => $token->plainTextToken];
});
laravel sanctum
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;
Route::post('/sanctum/token', function (Request $request) {
$request->validate([
'email' => 'required|email',
'password' => 'required',
'device_name' => 'required',
]);
$user = User::where('email', $request->email)->first();
if (! $user || ! Hash::check($request->password, $user->password)) {
throw ValidationException::withMessages([
'email' => ['The provided credentials are incorrect.'],
]);
}
return $user->createToken($request->device_name)->plainTextToken;
});
laravel sanctum
composer require laravel/sanctum
laravel sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
laravel sanctum
window.Echo = new Echo({
broadcaster: "pusher",
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted: true,
key: process.env.MIX_PUSHER_APP_KEY,
authorizer: (channel, options) => {
return {
authorize: (socketId, callback) => {
axios.post('/api/broadcasting/auth', {
socket_id: socketId,
channel_name: channel.name
})
.then(response => {
callback(false, response.data);
})
.catch(error => {
callback(true, error);
});
}
};
},
})
laravel sanctum
axios.defaults.withCredentials = true;
laravel sanctum
use Illuminate\Http\Request;
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us