samedi 2 juillet 2016

Laravel Category Filter

I have a laravel application which allows users to sign up and add all their workshops, each of the users can add members of their team and once checked the team member is verified.

When a visitor to my application views a category of workshops at the moment gets displayed all workshops in that category, I now want to add an additional feature which allows the visitor to filter the workshops in that category to only show verified workshops.

I have a the following tables

Users Companies Team Members Workshops Categories

I've created all the relationship tables and it all works fine, I just can't apply the filter.

For example when a visitor loads the following url, they shown workshops in that category:

http://ift.tt/29ce1GF

Heres the query I've wrote which should return only verified workshops in the category visited.

$verified = Req::get('verified');
        $preferred = Req::get('preferred');

        $category = Workshopcategory::where('slug',$id)->first();  

        if($verified == 'true'){
            return Workshop::whereHas('people', function ($query) {
                $query->where('verified', '=', true);
            })->where('categories',function ($query) use ($category) {
                $query->where('type_id','=', $category->id);
            })->get();
        };

        return view('site/category',compact('category'));

usually on the category without the filter I would use a foreach on the category variable as I have relationship defined but that doesn't contain the verified workshops. For testing if the url had the GET variable verified then I return the query above.

error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'categories' in 'where clause' (SQL: select * from `workshops` where (select count(*) from `team_members` where `team_members`.`company_id` = `workshops`.`comp_id` and `verified` = 1) >= 1 and `categories` = (select * where `type_id` = 1))



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire