将变量添加到Laravel的自定义表中
我有一个表,这是3个表格的组合,传递给了我的刀片文件。
$late_books = Borrow::join('books', 'borrows.book_id', '=', 'books.id')
->join('borrowers', 'borrows.borrower_id', '=', 'borrowers.id')
->where('borrows.late_return_status', '=', 1)
->where('borrows.return_date', '=', null)
->get(['borrowers.borrower_name', 'borrowers.IC', 'borrowers.phone_no' ,'books.ISBN', 'books.book_title', 'books.year','books.author', 'books.publisher_name',
'borrows.issue_date', 'borrows.due_date']);
在刀片文件中,我需要添加一个具有罚款的按钮。
$due_date = \Carbon\Carbon::parse($late_books->first()->due_date);
$today = \Carbon\Carbon::now();
$result = $due_date->diffInDays($today);
$fine = $result * 5;
罚款应特定于每本借来的书,目前的IVE完成方式对所有书籍均显示出同样的罚款。
return view('admin.latereturn', compact('late_books', 'search', 'fine'));
我确定以前以某种形式提出过这个问题,但我不确定要搜索什么。对不起,如果这是重复的。
I have a table which is a combination of 3 tables being passed to my blade file.
$late_books = Borrow::join('books', 'borrows.book_id', '=', 'books.id')
->join('borrowers', 'borrows.borrower_id', '=', 'borrowers.id')
->where('borrows.late_return_status', '=', 1)
->where('borrows.return_date', '=', null)
->get(['borrowers.borrower_name', 'borrowers.IC', 'borrowers.phone_no' ,'books.ISBN', 'books.book_title', 'books.year','books.author', 'books.publisher_name',
'borrows.issue_date', 'borrows.due_date']);
Within the blade file, i need to add a button which has the fines.
$due_date = \Carbon\Carbon::parse($late_books->first()->due_date);
$today = \Carbon\Carbon::now();
$result = $due_date->diffInDays($today);
$fine = $result * 5;
The fine should be specific to each book borrowed, the current way ive done it shows same fine for all books.
return view('admin.latereturn', compact('late_books', 'search', 'fine'));
Im sure this question has been asked in some form before but im not exactly sure what to search. Sorry if it's a duplicate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我得到您,
您可以在模型中定义一个添加属性的登录器,如下所示:
您可以访问刀片内部的精细属性,为$ model_instance->很好,
我希望对您有所帮助
If i get you
you can Defining An Accessor for appending attribute inside your model as the following:
and you can access fine attribute inside your blade as $model_instance->fine
I hope this helpful for you