-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using with Eloquent, not just Laravel's QueryBuilder #49
Labels
Comments
@lachlanhickey, kind of. It depends on what exactly you are trying to achieve, but you can usually do something along the lines of this: class Author extends \Illuminate\Database\Eloquent\Model {
// ....
}
$author = new Author();
// https://github.com/illuminate/database/blob/1e4476bac20b5c5e558efa02c4fb0ad46efd8013/Eloquent/Builder.php#L1353-L1361
$table = $author->getQuery();
$qbp = new QueryBuilderParser(
// provide here a list of allowable rows from the query builder.
// NOTE: if a row is listed here, you will be able to create limits on that row from QBP.
array( 'name', 'email' )
);
$query = $qbp->parse($input['querybuilder'], $table); |
For future reference. If someone wants to use the accessors or model relations of the result you could hydrate the results. $table = DB::table('models')
// join the relation(s)
->leftJoin('relations', 'relations.id', '=', 'other_table.relation_id');
$qbp = new QueryBuilderParser(
// provide here a list of allowable rows from the query builder.
// NOTE: if a row is listed here, you will be able to create limits on that row from QBP.
array( 'name', 'email' )
);
$query = $qbp->parse($input['querybuilder'], $table);
$rows = $query->get();
$models = Model::hydrate($rows->all()); Then as usual foreach($models as $model)
{
echo $model->accessor;
echo $model->relations->foo;
} |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just wondering if collections are supported with this package? Or only DB:: queries?
The text was updated successfully, but these errors were encountered: