Answer the question
In order to leave comments, you need to log in
Laravel connection data insertion?
There are 2 tables, they are connected to each other.
// table book:
$table->bigIncrements('id');
$table->bigInteger('book_language_id')->unsigned()->nullable();
$table->foreign('book_language_id')->references('id')->on('book_languages');
// table:book_languages
$table->bigIncrements('id');
$table->char('name',255);
class BookLanguage extends Model
{
public function book(){
return $this->belongsTo(Book::class);
}
}
class Book extends Model
{
protected $guarded = [];
public function language(){
return $this->hasOne(BookLanguage::class,'id','book_language_id');
}
}
$book=Book::create(['name'=>'books','ISBN'=>'123123','book_language_id'=>1]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question