0

I am trying to convert the following query to Laravel:

select libéllé
from application 
where libéllé not in (select application_id from application_user 
where user_id = $id)
2
  • docs will help you laravel.com/docs/5.4/queries#selects Commented Apr 30, 2017 at 8:12
  • May we see your attempt, Wahib? Commented Apr 30, 2017 at 8:15

2 Answers 2

1

Laravel whereNotIn supports closures for subqueries, so it will be as simple as this:

Using Eloquent:

// Add this to top of your file.
use App\{ Application, ApplicationUser };

// Get your entries.
$rows = Application::whereNotIn('libéllè', function($query) use ($id) {
    $query->select('application_id')->from((new ApplicationUser)->getTable())->where('user_id', $id);
})->get(['libéllè']);

Using Query Builder:

$rows = DB::table('application')->whereNotIn('libéllè', function($query) use ($id) {
    $query->select('application_id')->from('application_user')->where('user_id', $id);
})->get(['libéllè']);
Sign up to request clarification or add additional context in comments.

Comments

0

Please Try it.

$results = DB::select(
    select libéllé
from application 
where (libéllé)
 not in(
        select application_id from application_user     
     where user_id = $id
    ) 
);

Also see this answer: How to convert mysql to laravel query builder

Also see this documentation: https://laracasts.com/discuss/channels/laravel/laravel5-resolve-username-from-2-tables?page=1

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.