我有2个表,一个是问题,另一个是添加。两者在数据库中都具有相同的字段book_id
。我想在发布问题表时添加减去。我添加了quantity(int)
字段,其中数量的总值应减去发布表中发出ID的时间。
<!--controller-->
$data = DB::table('library')
->join('issue','library.book_no','=','issue.book_no')
->select('issue.book_no','library.isbn_no','library.book_no','library.book_title','book_type','library.author_name','library.quantity','library.edition','library.price','library.publisher_name')
->get();
return view('library.librarylist',['librarys'=>$data]);
@foreach($librarys as $library)
<tr>
<td><a href="{{route("admin.libraryissue", $library->id)}}">{{$library->book_no}}</a></td>
<td>{{$library->isbn_no}}</td>
<td>{{$library->book_title}}</td>
<td>{{$library->book_type}}</td>
<td>{{$library->author_name}}</td>
<td>{{$library->quantity}} | </td>
<td>{{$library->edition}}</td>
<td>{{$library->price}}</td>
<td>{{$library->publisher_name}}</td>
<td><button class="btn btn-default btn-xs "><a href="{{route("admin.Editlibrary", $library->id)}}">Edit</a></button> | <button class="btn btn-danger btn-xs btn-detail open-modal" type="submit" data-toggle="modal" data-target="#delID">Delete</button></td>
</tr>
@endforeach
答案 0 :(得分:0)
如果您在从问题控制器发出图书时搜索减少数量,可以通过以下方式减少图书馆表格中的数量: -
App\library::where('book_id',[Library_book_ID])
->update(['quantity' => DB::raw('quantity-1')]);
并且数量您可以从数量编号中获取可用图书的编号。