Vote count:
0
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
asked 1 min ago
Laravel 4 eloquent query returns an old database value instead of the updated one
Aucun commentaire:
Enregistrer un commentaire