Use Laravel repositories with Datatables
I don't think that there is a need of creating presenter , i suggest to make things more simple (its actually my practice).
i put my datatable implementation in my repository class :
use Prettus\Repository\Eloquent\BaseRepository;class MyRepository extends BaseRepository{ // .... public function getDatatable() { $images = $this->model->select('*'); return Datatables::of($images) ->addColumn('action', function ($p) { return '<a class="btn btn-xs btn-danger" onclick="return confirm(\'Delete this image ?\');" href="'.action('Dashboard\\ImagesController@destroy', ['id'=>$p->id]).'"><i class="glyphicon glyphicon-remove"></i> Delete</a>'; }) ->addColumn('image', function ($p) { return '<a href="'.$p->getMedia()[0]->getUrl().'"><img src="'.$p->getMedia()[0]->getUrl().'" class="img-responsive"></a>'; }) ->editColumn('created_at', '{!! $created_at->diffForHumans() !!}') ->make(true); }}
and then simply on your controller
namespace Admin\Http\Controllers;use App\Repositories\Contracts\ModuleRepository;class ModuleController extends Controller{ protected $repository; // ....... /** * Render a datatable instance */ public function datatable() { return $this->repository->getDatatable(); }}