O
O
ortsuev332019-08-22 14:08:39
Laravel
ortsuev33, 2019-08-22 14:08:39

Why can't I access the model method for the link?

BadMethodCallException
Method Illuminate\Database\Eloquent\Collection::category does not exist.
-------------------------------------------------- ------------------------------------

if($take) {
      $builder->take($take);
    }
    
    if($where) {
      $builder->where($where[0],$where[1]);
    }
    
    if($orderBy){
      $builder->orderBy('id','DESC');
    }
    if($pagination) {
      $builder->paginate(Config::get('settings.paginate_home'));
    }
$articles=$builder->category();

roughly speaking, I want to make in one table (selection) then by connection in the second category table
, well, when accessing the function, the psht does not exist, although I registered the connection method in the article model

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Vorotnev, 2019-08-22
@ortsuev33

From what I see, $builderyou have a collection, and the method category()is probably a method of the model, which, in theory, should be in this collection. The collection itself has no such method, hence the Exception. Looks like it will help you $builder->first()->category().

O
oleg_ods, 2019-08-22
@oleg_ods

$builder you most likely have selection parameters, and not an article object. Accordingly, the connection here and should not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question