I have 2 tables
named Company
and Customer
. One-to-Many relationship, where a company can have many customers and a customer belongs to this company.
Company Table Customers Table
Company Id, Customer_ID,
Company Name, Customer_Name,
Company Address Phone_no.
In the seeder,
factory(App\Company::class, 5)->create()->each(function ($data) {
$customers= factory(App\Customer::class, 5)->make();
$data->customers()->saveMany($customers);
});
so, each company generates 5 customers each.
The Idea is
company_id customerId
1,1,1,1,1 1,2,3,4,5 // the customerId should not be repeated again like 1,2,2,3,4,
2,2,2,2,2 2,3,6,7,8 // should not be 2,3,3,3,6
3,3,3,3,3 5,7,8,9,2 and so on
A company can have many customers but not the customer's with the sameId.
How to avoid the duplication for the customerID using php?, and a condition to check if the company has already the customer with the SameId, then remove them from the customer?
Could anyone please help?
Thanks.