Pavan Tolety Pavan Tolety - 1 month ago 5
MySQL Question

I need to match a String in MySql query in Laravel

I need to use a query which perfectly works in MySql. and query is

SELECT * FROM c2cxdb.jobs where job_title like '%Java%' and job_policy = 'Public' and job_status = 1;


where I need to replace java inside %% with a dynamic value that I pass to the method.

function AllJobs($job_title){
$allJobs = DB:: select('select * FROM c2cxdb.jobs where job_title like '%$job_title%' and job_policy = "Public" and job_status = 1');
dd($allJobs);
}


But It shows Division by zero exception when I run it.How to replace the value in my query with the value I Pass.I need to get the $job_title value into query.

Answer
function AllJobs($job_title){
    $allJobs = DB:: select('select * FROM c2cxdb.jobs where job_title like "%'.$job_title.'%" and job_policy = "Public" and job_status = 1');
    dd($allJobs);
}
Comments