我如何在 laravel 中用 eloquent 从数据库中检索 created_data?,我使用的是属于多个关系,我想显示借书数据和借阅日期,我已成功显示借书数据,但我无法获取 created_at 数据来自数据库中另一个名为 borrow_history 的表
书本.php
public function borrowed()
{
return $this->belongsToMany(User::class, 'borrow_history')
->withTimestamps();
}
用户.php
public function borrow(){
return $this->belongsToMany(Book::class, 'borrow_history')
->withTimestamps();
}
这是我当前的 HomeController.php 索引
public function index()
{
$books = auth()->user()->borrow;
return view('home', [
'books' => $books,
]);
}
我想在 home.blade.php 显示 created_at 数据
@foreach($borrow_history as $borrow)
<p>
<i class="material-icons">date_range</i> Borrow_date : {{ ???? }}
</p>
@endforeach
谁能帮我?
白板的微信