0

who can help me? I was selected from sql. This is my sql. How to create with Laravel query in controller.

SELECT 
    `sp`.name_en,
    `sp`.email,
    `sp`.phone,
    `post`.`name` 
    AS 
    `position_name`
FROM 
    `staff_profiles` `sp`
INNER JOIN 
    `staff_positions` `p`
INNER JOIN 
    `positions` `post`
WHERE
    `sp`.id=`p`.`staff_id` AND `p`.`position_id`=`post`.id

2 Answers 2

2

You can use the Query Builder to build the same query: https://laravel.com/docs/5.4/queries

Or you can just run your raw query using the DB Facade: https://laravel.com/docs/5.4/database#running-queries

Something like this:

DB::select('SELECT  sp.name_en, sp.email, sp.phone, post.name AS  position_name FROM staff_profiles sp INNER JOIN  staff_positions p INNER JOIN  positions post WHERE sp.id=p.staff_id and p.position_id=post.id');
Sign up to request clarification or add additional context in comments.

Comments

0

Include you model like use BusinessObject\User; than following query is example query.

$matchThese = ["job_comments.status" =>1,'job_id'=>$job_id];
        $job_com = DB::table('job_comments')
            ->select('job_comments.*','users.id as userid','users.first_name','users.last_name','users.image','users.role')
            ->where($matchThese)
            ->join('users', 'job_comments.commenter_id', '=','users.id' )
            ->get();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.