I have model
Project which has some
$appends and some relations like
$appends it has
pages, and in
Page model it has lot of other
$appends. Now while I do
Project::find($id) it retrieves project, it’s pages and other models which belongs to Page.
And I havn’t done
with, so for each page it fires lots of queries.
Is there any better approach to load only Project model, no relation, no appends, nothing via Eloquent ?
Unfortunately thats not how it works. If you want to remove the appends you could do so as follows:
$project = Project::find(1); $project->setAppends(); return $project; //no values will be appended
However if those appends are doing database calls and you prefer not to you should rexamine whether or not it makes sense for the appends to be there. It’s really a matter of whether you think it makes sense for the
appends to always be included or not.
Answered By – Alex Harris
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0