一,主表book
class Book extends Model
{
//
protected $fillable=['title','price','num'];
public function bookCard(){
return $this->hasOne(BookCard::class);
}
}
二,关联表bookcard
class BookCard extends Model
{
//
protected $fillable=['number'];
public function book(){
return $this->belongsTo(Book::class);
}
}
三,主表和关联表如何写
$booklist=Book::find(1);标签:Laravel,function,fillable,一对一,bookCard,深入研究,Book,主表,class From: https://www.cnblogs.com/96net/p/17811330.html
$res=$booklist->bookCard()->create([
'number'=>str_random(16),
]);