Grace
Grace

Reputation: 299

Laravel Auditing BadMethodCallException Method audits does not exist

I'm using laravel auditing, Link and I have use it with my controller and it was working fine, now my problem is when I apply it to another controller is does work, is it only allowed to use once? my method all the same I'm just confuse why it doesn't work.

First controller code (WORKING FINE)

 $leads = Lead::findOrFail($id);
 $audit=Lead::findOrFail($id)->audits()->with('user')->get()->last();

Second Controller code: (Not Working Error: Method audits does not exist.)

  $scores = Score::with(['lead','subject'])->where(['subject_id'=>$id])->get();
  $audit = $scores->audits()->with('user')->get()->last();

Upvotes: 0

Views: 184

Answers (1)

Homer
Homer

Reputation: 467

Don't know what Laravel auditing is, but my good guess is, your first one is a object, so you can apply your audit() method on it directly, but the second one, $scores, is a collection of objects, you surely can not directly apply a method call on it, try to iterate it, should be fine.

Upvotes: 0

Related Questions