bosnadev / repository

Laravel Repositories is a package for Laravel 5 which is used to abstract the database layer. This makes applications much easier to maintain.
https://bosnadev.com
825 stars 235 forks source link

update method not working #27

Closed jdsingh closed 9 years ago

jdsingh commented 9 years ago

I'm using mongoDB as database and https://github.com/jenssegers/laravel-mongodb package.

When I run this code $this->user->update($request->all(), $id);, it executes fine but the data is not being updated in database.

Version info "laravel/framework": "5.0.*", "jenssegers/mongodb": "~2.1",

RiCi12 commented 9 years ago

I can say the same thing: using sqlite (with default PDO and driver), update method does not acctualy affect data in the DB.

I'm using the "dev" version of the package, from packagist.

stuarthannig commented 9 years ago

I didn't try update with this package, but I wasn't seeing the results either when doing it from straight Elequent on MySQL. Might be related.

RiCi12 commented 9 years ago

It could be. I've spent some time fixing the bug, however i wasn't able to solve the problem, either with some errorproof code for laravel 4.2/5.0. Maybe some bug introduced in recent laravel/symfony? Il 11/mag/2015 18:46, "Stuart Hannig" notifications@github.com ha scritto:

I didn't try update with this package, but I wasn't seeing the results either when doing it from straight Elequent on MySQL. Might be related.

— Reply to this email directly or view it on GitHub https://github.com/Bosnadev/Repositories/issues/27#issuecomment-100975405 .

robertvrabel commented 9 years ago

My problem is it is trying to update _method and _token in the DB since those are in the request object. Its not taking into account only the model's fields. Anyone also run into this issue?

jdsingh commented 9 years ago

@robertvrabel Did you try $request->except('_method', '_token') ?

robertvrabel commented 9 years ago

@jdsingh Yeah i did. I can get it to work doing that, but it seems like unnecessary overhead? I'd hate to have that lingering all over the place.

jdsingh commented 9 years ago

@robertvrabel yeah that looks bit dirty, it should work with model's fill-able property but still yours work with that.

I have to use this

$model = $this->model->find($id);
$model->update($request->all());
jdsingh commented 9 years ago

Got it working by specifying the primary key $attribute as mongodb uses "_id" as primary key.

$this->user->update($request->all(), $id, "_id");