Code Monkey home page Code Monkey logo

sanctum-tokens's Introduction

Create a Sanctum Personal Access Tokens in Nova

This package allows you to use Sanctum to generate a Personal Access Tokens in Nova.

Screenshot

screenshot of providing a name screenshot of providing a name screenshot of providing a name

Prerequisites

  1. Install and Configure Sanctum
  2. Have Laravel Nova

Installation

composer require jeffbeltran/sanctum-tokens

Register the plugin by adding SanctumTokens::make() to the array of fields in the Nova resource. Make sure the HasApiTokens trait from the Sanctum package has been added to your model.

use Jeffbeltran\SanctumTokens\SanctumTokens;

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        ID::make('ID', 'id')->sortable(),
        ...
        SanctumTokens::make(),
    ];
}

Features

Hide Abilities

You can hide the reference to the token abilities from the UI by calling the hideAbilities() method on the field.

use Jeffbeltran\SanctumTokens\SanctumTokens;

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        ID::make('ID', 'id')->sortable(),
        ...
        SanctumTokens::make()->hideAbilities(),
    ];
}

Set Default Abilities

If you don't want to use the default * token ability you can set your own by simply passing an array of strings to the defaultAbilities() method on the field.

This works well with the the hideAbilities() method if you want to hide the abilities logic from your users.

use Jeffbeltran\SanctumTokens\SanctumTokens;

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        ID::make('ID', 'id')->sortable(),
        ...
        SanctumTokens::make()->defaultAbilities(['foo', 'bar-baz']),
    ];
}

Localization

Publish the package language files to your application's resources/lang/vendor directory:

php artisan vendor:publish --provider="Jeffbeltran\SanctumTokens\ToolServiceProvider"

sanctum-tokens's People

Contributors

jeffbeltran avatar semantic-release-bot avatar dependabot[bot] avatar craftyshaun avatar aaronflorey avatar anibalsanchez avatar chrisbjr avatar ryanmitchell avatar theofanisv avatar tpetry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.