I have a Book table that has a column for stocks count.For example the beginning stocks of a certain book is 100.
BOOKS
book_id | book_stocks
1 | 100
when i run this code it will output '100'.
$book = Book::where('book_isbn','=',$credentials['book_isbn'])->get();
foreach ($book as $b) {
echo $b->book_stocks;
}
then a part of my code will decrement this stock once a user reserves a book. here's the code.
Book::where('book_isbn','=',$credentials['book_isbn'])->decrement('book_stocks');
when i check my database it now becomes
BOOKS
book_id | book_stocks
1 | 99
but when i run this code again.
$book = Book::where('book_isbn','=',$credentials['book_isbn'])->get();
foreach ($book as $b) {
echo $b->book_stocks;
}
the output is still '100'. I don't know where it saves that old stock value. I'm sure with my database connection, i tried to clear cache etc. do anyone knows the reason behind this? Thanks in advance
Try to load the corresponding model and print the stock value afrer the decrement execution. The existing data how inserted in database? May you run this code again; Do you use a seed class;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community