Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mohamadAbdelhady's avatar

how to excute this query in laravel?

the query I want to excute in laravel in pure sql

SELECT p.id,title,post_content,image_dir,video_dir,p.created_at,first_name,last_name,profile_img FROM users AS u,posts AS p WHERE title like '%mo%' OR post_content like '%mo%' AND user_id=u.id
0 likes
3 replies
mohamadAbdelhady's avatar

thanks, it work, but the problem is that i want to replace mo with a variable name $key but when i tried to do that it didn't return any records

jlrdw's avatar
WHERE title like :key

$bindings = ['title' => "%" . $key . "%"];

Just like example in link. Do same for post_content.

Please or to participate in this conversation.