Answer the question
In order to leave comments, you need to log in
Where in Laravel to place duplicate requests?
Good afternoon. Sometimes there are cases when the SQL query almost completely or completely matches the one that was used before. Where to place this code and how best to reuse it?
Now, in the model I write something like this code
public static function selectDataReport($request)
{
return self::select('')
->leftJoin('')
->leftJoin('')
->with('test')
->where('id', '')
}
$data = MyClass::selectDataReport($request);
Answer the question
In order to leave comments, you need to log in
What you described looks like a model, only you need to pass inside not a request, but parameters, such as $id.
Regarding where the models are stored, it is written here:
In other words, you can store it in the app folder, but you are free to use another location for your models.
If one model is a method in the model or scope.
If this is for different models, then my choice is copy-paste. Well, or a trait in the model.
If for these different models the same type of reports are built, then I use
class ReportRepository{
function __construct(ReportableModelInterface $model){}
function getSimpleReportData($id){}
function getCustomReportData($id, $any){}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question