0
votes

I want to create dynamic laravel class , in order to call query dynamically . this is my code

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class CRUD extends Eloquent
    {   
        protected   $collection  ;
        function __construct($collection  ,  $attributes = array())
            { 

                $this->collection = $collection;
            }
    }

but when I am trying to call this class in order to create an object using this code

     $device_model = new CRUD('table');

I get this error

Too few arguments to function App\CRUD::__construct(), 0 passed in /var/www/html/logging/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 1630 and at least 1 expected

please help me in order to solve this problem , I am calling class in right way and passing the table name , but no success

1

1 Answers

0
votes

Try this:

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class CRUD extends Eloquent
{   
    protected $collection ;

    function __construct($collection  ,  $attributes = array())
    { 
        parent::__construct($attributes);

        $this->collection = $collection;

    }
}