I can use scopes to perform basic model-related queries (such as select those users who have a birthday today), scopes are obviously placed in Eloquent Models and return an instance of Eloquent Query Builder. But what if I need to perform a more complex query, say group a massive email log table by email type, join with users and emails and apply some aggregates? Since the resulting fields of the query are mixed (email, email type, user, log fields), I have to use Database Query Builder. I'm hesitating thinking of the best place for the call to the builder.
Is can be a static method in the main model where I join other tables to:
class ConcreteModel extends Model {
public static function someQuery(): \Illuminate\Database\Query\Builder {
return \DB::table('some_table')->join('something');
}
}
Or maybe rather to place such stuff in services that need it?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire