I have two tables:
user:
id, username, password
customers:
id, user_id, fullname, address
In my CustomerController.php, store() function I need to create user first and then customer with user_id.
Customer::create($request->all());
is inserting the customer data but without user_id
Is there anyway to add user and customer at once using Eloquent?
My User model is:
class User extends Authenticatable{
public function customers(){
return $this->hasMany('App\Customer', 'user_id');
}
}
Customer model
class Customer extends Model {
public function user(){
return $this->belongsTo('App\User');
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire