I suggest reading this one, it might help you
Extending tables and/or models
I'm hoping there is a way to do something like below:
- A number of tables have the same common fields, e.g. name, address, email, I place them in
partnerstable - The tables are
customers,suppliers,employeesetc - In PHP terms, think of it like,
class customers extends partners,class suppliers extends partnersetc - I understand the practice is to use roles and permissions to handle a partner being a customer or supplier
- But where would I store customer or supplier specific info?
- Is there a way I design the tables such that I can call
$customer->namewithout having to write a bunch of attributes?
@laracoft and to reduce the ->user, you are writing 5 lines of QueryBuilder?
Do you really want to sacrifice db performance, which mean potentially user experience; increase your app complexity, which mean more time and money will be spent, also making expandability and maintainability harder, all because of one less arrow?
On the other hand, as I said, you can name your relationship anything you want
$customer->accountInfo()->name();
does this look more readable to you?
This is how to achieve that:
class Customer ........
{
public function accountInfo() //previously user()
{
return $this->belongsTo(User::class);
}
}
Prioritize your app's structure first, there is no point in "readable code" if your app is a structural mess
Please or to participate in this conversation.