How to use Eloquent ORM of laravel to implement a complicated sql statement

SELECT t.*,u.`name` 
FROM template t 
INNER JOIN `user` u 
ON u.id = t.user_id
WHERE t.is_delete = 1 
AND ( t.title LIKE "%abc%" or u.`name` LIKE "%abc%" )

above are the sql statements I want to implement, and the model model relationships are all correct

.

what if it is paged on this basis

Mar.13,2021

Template::join('user', 'template.user_id', '=', 'user.id')
    ->where('is_delete', 1)
    ->where(function ($query) {
        $query->where('title', 'like', '%abc%')
            ->orWhere('user.name', 'like', '%abc%');
    })->skip(*(-1))->take()
    ->get();

you can try, it's written like this


paginate () or array_slice () handle it yourself

Menu