N
N
ngame2016-12-12 07:48:08
Laravel
ngame, 2016-12-12 07:48:08

Why doesn't Eloquent ORM want to update the model?

Good afternoon!
Laravel 5.3 does not want to update the eloquent model, while creating new ones with a bang! I wrote $fillable in the model, the result is the same. The debug went through the fields, the value was set to the right one, there were no errors when calling save () .. What am I doing wrong?

try {
            \DB::beginTransaction();

            /** @var vpStore $store */
            $store = vpStore::findOrFail($request->store);
            $date = new Carbon($request->date);
            $totalQty = (int) $store->Qty;
            $qty = (int) $request->qty;

            /** @var vpReport $report */
            $report = new vpReport();
            $report->StoreId = $store->Id;
            $report->Price = 0;
            $report->Qty = $qty;
            $report->Date = $date->format('Y-m-d H:i:s');
            $report->Type = vpReport::TYPE_CASH;
            $report->save();

            $store->Qty = $totalQty - $qty;
            $store->save();

            \DB::commit();
        } catch (QueryException $e) {
            \DB::rollBack();
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Plisko, 2016-12-12
@AmdY

DB::enableQueryLog();
DB::getQueryLog();

Plus, look at the logs, you never know what kind of error fell out . In
general, I advise you to re-read the laravel documentation.
Filleble has nothing to do with it, it works with a mass fill, and you have getters.
Write vpStore and vpReport link, use it.
Type casting in the controller looks ridiculous and useless, do such things inside models through setAttribute, the same applies to Carbon
Do not use facades, better inject the model, at the same time you will remove the crutch with phpdoc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question