The User model represents an authenticated user in the NetBird Selfservice application. It extends Laravel’s Authenticatable class and provides user management, authentication, and profile functionality.
// Create a single user for testing$user = User::factory()->create();// Create multiple users$users = User::factory()->count(10)->create();// Create user with specific attributes$admin = User::factory()->create([ 'email' => 'admin@example.com', 'name' => 'Admin User',]);
use App\Notifications\ResourceApproved;$user = User::find(1);// Send notification using the Notifiable trait$user->notify(new ResourceApproved($resource));// Send via specific channel$user->notifyNow(new ResourceApproved($resource));
// Get user's resources (requires Resource relationship)// Note: Add this relationship to the User model if needed// public function resources() {// return $this->hasMany(Resource::class);// }$user = User::with('resources')->find(1);$resourceCount = $user->resources->count();// Get user's pending requests$pending = PendingResource::where('user_id', $user->id) ->where('status', 'pending') ->get();
Password Hashing: Passwords are automatically hashed using the hashed cast. Never store plain-text passwords.
Hidden Attributes: The password and remember_token fields are automatically excluded from JSON responses and array conversions.
When creating users via OAuth (Google), you may not need to set a password. Ensure your authentication logic handles both password-based and OAuth users.