What you do (expanding the User model) is excellent, and the approach that I use myself in projects.
For example, if the Im building application has functions similar to a store, then I can create a Customer model that extends my User model and contains, for example, relations related to the order:
class Customer extends User { public function orders() { return $this->hasMany(Order::class, 'customer_id'); } public function worth() { return $this->orders()->sum(function ($order) { return $order->total(); }); } }
In a recent project, Ive worked on email functionality and created a Recipient class that extends the User model to add campaign-related methods:
class Recipient extends User { public function campaigns() { return $this->belongsToMany(Campaign::class, 'recipient_id'); } }
Since both of these classes extend the User model, I get all of these (and pronounced) methods:
$customers = Customer::with('orders')->get();
While you are setting up a table in your base User model, any classes that inherit it will use the same table, although the model can be named differently (i.e. Customer , Recipient , Student , etc.).
source share