This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

alexax
alexax

Hi all, I like to build a simple Linklist plugin for a local club here. i have a Categories and a Links table, they are in relation with a pivot table so i can handle one link in multiple categories. now i have a component that is placed in a partial file (two separete partial files) to use the component twice if needed.

on my Link List Page i like to show now all Links in the Categories - but w/o the links from one specific cat. i.e the category "frontpage" `
protected function loadCategories() { $query = Category::active()->with('links')->get();

        /*
        *
        *   Show a specific Category
        *
        */

        if( $this->property('cat_slug') <> 'all' ) {
        $query =  $query->where('slug', $this->property('cat_slug') )

                        ->take($this->property('results'));
        }

        /*
        *
        *   Show all Categories
        *   but NOT the one selected as 'exclude...'
        *
        */

        if( $this->property('exclude_cat') == 'frontpage')  {
            $query = $query->where('slug' , '<>', 'frontpage' )->take($this->property('results'));
            return $query;
        }

        return $query;
    }

` this returns nothing.... too bad.

now when i use the php code block on a testpage like this here:

<? use Alex\Linklist\Models\Category; function onStart(){

    $this['categories'] = Category::where('slug', '<>', 'frontpage')->with('links')->get();
}

?> ` it works as expected.

what am i doing wrong here ? thank you for your help

Sam
Sam

you need to add the onRun() method in your component class.

Last updated

alexax
alexax

Thank you for anwering Sam, in my on Run() method i call loadCategories()... .. so that should basically work.

I'll come back with more code after i give it another try this week. A

alex@work
alex@work

so, problem solved. it was a wrong eloquent query. i had to use the full model/query thingy inside the if() statement to get it going. if( bla = foo ){ $query = Category::active()->with('links') .. here my options.. }

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.