Answer the question
In order to leave comments, you need to log in
How to pull data from a table that is not in another laravel table?
Good afternoon, there are two tables
table_1
id | name
1 name_1
2 name_2
3 name_3
table_2
id | another_id | name
1 1 name_1
2 2 name_2
3 2 name_5
4 1 name_3
you need to pull out the name from the table table_1 which is not in table_2 and also so that it does not match the another_id field
return DB::table('table_1')
->leftJoin('table_2', 'table_1.name' , '=' , 'table_2.name')
->where('table_2.name', null) ->where('table_2. another_id' ,'!= ', $id)
->select('table_1.name' )
->get();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question