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

Unable Create Record With Beanstalkd Queue #65

Closed fer-ri closed 8 years ago

fer-ri commented 8 years ago

Hi

do you ever face problem that you cant insert/create any record when queue driver set as beanstalkd ?

i always got

Trying to get property of non-object 

Seems like $this->model got undefined and error above got triggered when execute this line

return $this->model->create($data);

my code is pretty simple

<?php

// controller
        $this->dispatch(
            new \Modules\Accounting\Jobs\HitungAdministrasiSimpanan('fa108a98-cd89-402e-b60f-bb1b039c2606')
        );

// job
        $transactionRepository = app()->make(TransactionRepository::class);

        // .. rest code ...

        $transactionRepository->create([
                'reference'   => 'SLUG',
                'nominal'     => 0,
                'description' => 'BLANK',
            ]);

But when queue driver back to sync then everything is ok ..

Any idea?

Thanks

hananbo commented 8 years ago

Hey, if you're using an up to date laravel then the create method in Illuminate\Database\Query is now called "insert", just change the method name in your repository abstract class and in your repository interface to insert instead of create. then just call insert instead of create: $transactionRepository->insert([ 'reference' => 'SLUG', 'nominal' => 0, 'description' => 'BLANK', ]);

fer-ri commented 8 years ago

ah my bad this is an old issue that already solved .. sorry for bothering you :)