I am using GitHub - jenssegers/laravel-mongodb: A MongoDB based Eloquent model and Query builder for Laravel; In my Laravel project I created DB model that sets Model table name dynamically (in Mongodb case collection) .
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class DbData extends Model
{
protected $collection = 'default_collection';
function __construct($collection)
{
$this->collection = $collection;
}
}
This works when I am creating new DbData object, for data insert:
$data = new DbData('dynamic_collection_name');
$data->variable = 'Test';
$data->save();
But this solution is not enough of I want to use this DbData model for querying data from my database. What I want to achieve is to add possibility to pass variable for DbModel, for instance something like this:
$data = DbData::setCollection('dynamic_collection_name');
$data->get();