php - Laravel: Pass Parameter to Relationship Function? -


is possible pass, somehow, parameter relationship function?

i have following:

public function achievements() {      return $this->belongstomany('achievable', 'user_achievements')->withpivot('value', 'unlocked_at')->orderby('pivot_unlocked_at', 'desc'); } 

the problem that, in cases, not fetch unlocked_at column , returns error.

i have tried like:

public function achievements($orderby = true) { $result = $this->belongstomany (...) if($orderby) return $result->orderby(...) return $result; } 

and call as:

$member->achievements(false)->(...) 

but not work. there way pass parameters function or way check if pivot_unlocked_at being used?

well i've did adding new attribute model , add condition attirbute,simply did this.

class foo extends eloquent {     protected $strslug;      public function relations(){          return $this->belongsto('relation','relation_id')->whereslug($this->strslug);     }  }   class foocontroller extends basecontroller {      private $objfoo;        public function __construct(foo $foo){          $this->objfoo = $foo      }       public function getpage($strslug){         $this->objfoo->strslug = $strslug;         $arrdata = foo::with('relations')->get();         //some other stuff,page render,etc....      }  } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -