DeveloperBreeze

Custom Model Development Tutorials, Guides & Insights

Unlock 1+ expert-curated custom model tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your custom model skills on DeveloperBreeze.

Tutorial

Creating Personal Access Tokens for a Custom Model in Laravel

use Laravel\Sanctum\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Customer extends Authenticatable
{
    use HasApiTokens;

    protected $fillable = ['name', 'email'];

    // Define the relationship with tokens
    public function tokens()
    {
        return $this->morphMany(\Laravel\Sanctum\PersonalAccessToken::class, 'tokenable');
    }
}

The HasApiTokens trait adds the ability to issue tokens to the Customer model.

Oct 24, 2024
Read More