Reputation: 6462
Let me show you my eloquent ORM class:
<?php
namespace App\Http\Models\Transport_Type;
use Illuminate\Database\Eloquent\Model;
use App\Http\Models\Transport_Type\TransportType;
class TransportType extends Model{
public $timestamps = false;
public function foo($language_id){
$transport_types = TransportType::join('translations', 'transport_types.name', '=', 'translations.id')
->join('translation_entries', 'translations.id', '=', 'translation_entries.translation_id')
->where('translation_entries.language_id', '=', $language_id)
->orderBy('parent_id')
->get(['transport_types.id', 'transport_types.parent_id', 'translation_entries.value']);
return $transport_types;
}
}
As you see I have foo function which I can call from many different controllers. so here is my question: Is it a good practice? or should I move that query logic to controller?
Upvotes: 0
Views: 64
Reputation: 101
I prefer to keep my eloquent models and controllers as empty as possible, because of that I prefer to have repositories where I handle all my data access. See https://medium.com/employbl/use-the-repository-design-pattern-in-a-laravel-application-13f0b46a3dce for examples how to do this in Laravel.
Edit: I'm not sure of your approach is a bad of good practice. Just wanted to share my opinion maybe it helps :)!
Upvotes: 1