Is it difficult to open the documentation and read?
https://datatables.yajrabox.com/eloquent/joins
https://yajrabox.com/docs/laravel-datatables/master/engine-eloquent
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
The docs show that you need a Model that corresponds to the DataTable:
public function query(User $model)
{
return $model->newQuery();
}
But what if I have some more complex query that is not a Model? For example:
return $data = Auth::user()->select(//...)
->where(//...)
->where(\DB::raw(//...))
->leftJoin(//...)
->get();
How to make it work with Yajra?
@cooperino From the documentation....
$posts = Post::join('users', 'posts.user_id', '=', 'users.id')
->select(['posts.id', 'posts.title', 'users.name', 'users.email', 'posts.created_at', 'posts.updated_at']);
return Datatables::of($posts)->make(true);
Do you see ->get() there? No!
Please or to participate in this conversation.