laravel - SQL Join/LeftJoin Statement Returning Null -


i'm trying join 2 queries statement:

$item = category::where('type', $item)               ->leftjoin('inventory', 'inventory.id', '=', 'categories.id')               ->get();  return view::make('general.buy')                 ->with('items', $item); 

this view (this returns null):

@foreach ($items $item)   {{ $item->id }}  @endforeach 

the problem if there no inventory id value equal category id field, query returns id null.

does know why happening , how can solve it? should mention new laravel, please keep in mind when rating question. in advance!

i think answered own question. it's more left join means. have 2 tables, inventory , category correct? according query (or @ least can tell) generate sql simliar to

select category left join inventory on inventory.id = categories.id 

this says, select rows category , if have match in inventory fill in columns queried (inventory.id) supply value, otherwise return null in column.

given seems unexpected result you, can't notice naming convention seems off (but i'm not familiar laravel). assume instead of merging on categories.id merge on category.id (which seem match rest of schema).

based on , how you're querying, results appear correct.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -