I croak that there is something that escapes me.
I have a User model that has a hasMany relationship with another model called Domain
I thought it is possible to save the data in both tables in a single command but I see that it is not or not.
Tinker
use App\Models\Albarid\Domain;
$domain = new Domain;
use App\Models\Albarid\User;
$user = new User;
$user->name = 'Jhon Doe';
$user->email = 'mailo@ggmaiol.com'
$user->password = 'hajsdkjhaksdjkhas';
$user->c_password = 'hajsdkjhaksdjkhas';
$domain->domain = 'newdomain.com';
$user->domains()->save($domain)
Illuminate/Database/QueryException with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_id' cannot be null (SQL: insert into `domains` (`domain`, `user_id`, `updated_at`, `created_at`) values (nuewdomain.com, ?, 2019-09-30 11:31:47, 2019-09-30 11:31:47))'
Is possible one way for save data in two tables in one command or need create first user?
but no.
I write the most widespread code since the problem of connections does not seem to be.
>>> use App\Models\Albarid\Domain;
>>> $col = Schema::getColumnListing('domain')
=> []
>>> $domain = new Domain;
=> App\Models\Albarid\Domain {#3140}
>>> use App\Models\Albarid\Domain;
>>> $domain = new Domain;
=> App\Models\Albarid\Domain {#3136}
>>> $domain->getTableColumns()
=> [
"id",
"user_id",
"domain",
"description",
"disclaimer",
"aliases",
"mailboxes",
"maillists",
"maxquota",
"quota",
"transport",
"backupmx",
"settings",
"created_at",
"updated_at",
"deleted_at",
"full_deleted_at",
]
>>> $user->getTableColumns()
=> [
"id",
"name",
"email",
"email_verified_at",
"password",
"remember_token",
"is_super_admin",
"created_at",
"updated_at",
]
Relationship exists
public function domains()
{
return $this->hasMany('App\Models\Albarid\Domain');
}
There're a piece of problem.
I've multiple conecctions and also in User model use trais HasApiTokens
After see this, I think the problem is other question., I apologize for inconvenients.