Skip to main content

Overview

The User model extends Laravel’s Authenticatable class and implements email verification. It represents users who can manage their accounts, categories, transactions, and track their net worth.

Properties

id
integer
required
Unique identifier for the user
name
string
required
The user’s display name
email
string
required
The user’s email address (must be unique)
email_verified_at
datetime
Timestamp when the email was verified
password
string
Hashed password (nullable for social authentication users)
remember_token
string
Token for “remember me” functionality (hidden from serialization)
provider
string
OAuth provider name (e.g., ‘google’, ‘github’) for social authentication
provider_id
string
Unique identifier from the OAuth provider
created_at
timestamp
When the user was created
updated_at
timestamp
When the user was last updated

Fillable Attributes

The following attributes can be mass-assigned:
  • name
  • email
  • password
  • provider
  • provider_id

Hidden Attributes

These attributes are hidden from serialization for security:
  • password
  • remember_token

Relationships

accounts()

Returns all accounts belonging to the user. Type: HasMany Returns: Illuminate\Database\Eloquent\Relations\HasMany
$user->accounts; // Collection of Account models

categories()

Returns all categories created by the user. Type: HasMany Returns: Illuminate\Database\Eloquent\Relations\HasMany
$user->categories; // Collection of Category models

transactions()

Returns all transactions belonging to the user. Type: HasMany Returns: Illuminate\Database\Eloquent\Relations\HasMany
$user->transactions; // Collection of Transaction models

netWorth()

Returns all net worth records for the user. Type: HasMany Returns: Illuminate\Database\Eloquent\Relations\HasMany
$user->netWorth; // Collection of NetWorth models

Methods

isSocialiteUser()

Determines if the user authenticated via a social provider (OAuth). Returns: boolean Description: Returns true if the user has no password set, indicating they use social authentication.
if ($user->isSocialiteUser()) {
    // User authenticated via OAuth provider
}

Traits

  • HasFactory - Enables model factories for testing
  • Notifiable - Adds notification capabilities

Interfaces

  • MustVerifyEmail - Requires email verification for authentication

Example Usage

use App\Models\User;

// Create a new user
$user = User::create([
    'name' => 'John Doe',
    'email' => '[email protected]',
    'password' => bcrypt('secret'),
]);

// Access user's accounts
$accounts = $user->accounts;

// Get user's transactions
$transactions = $user->transactions()->latest()->get();

// Check if social auth user
if ($user->isSocialiteUser()) {
    echo "User signed in with {$user->provider}";
}

Build docs developers (and LLMs) love