mercredi 1 mars 2017

Laravel DB query gives a set of results different from direct MySQL query

I am trying to execute the following query in MySQL

SELECT * FROM categories AS subcategory JOIN categories AS parent ON parent.category_id = subcategory.parent_category_id WHERE subcategory.category_display_type = 'sidebar' AND subcategory.category_visibility = 1

like so:

class SidebarnavComposer
{
    public function compose(View $view)
    {
        $params = DB::table('categories as subs')->join('categories as cats', function($join){
                $join->on('subs.parent_category_id', '=', 'cats.category_id')
                ->where('subs.category_display_type', '=', 'sidebar')
                ->where('subs.category_visibility', '=', 1);
    })->get();


        $view->with('subcategories', $params);

    }

the problem is that I get different set of results.

When I use the first query directly in MySQL I get the following:

category_id
category_id1
category_title
category_title1
category_slug
category_slug1
.......

when I execute the second query in my laravel application I get the following set of results:

category_id
category_title
category_slug
.......

this basically means that I cannot access all necessary columns.

I am not sure what I am doing wrong as I am new to laravel and at the moment do not really know much, so please help me if you can



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mcLZlB
via IFTTT

Aucun commentaire:

Enregistrer un commentaire