Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

boyjarv's avatar

Collection::with does not exist.

{"error":"Failed to get comments for transactions - Method Illuminate\Database\Eloquent\Collection::with does not exist."}

public function getTransactionComments()
    {
        $query = Comment::get();
        
        $comments = $query->with('payment')->with('club')->orderBy('created_at', 'ASC');
        
        return $comments;
    }
0 likes
4 replies
MichalOravec's avatar
Level 75

Is it not clear for you?

public function getTransactionComments()
{
    return Comment::with(['payment', 'club'])->orderBy('created_at')->get();
}
2 likes
boyjarv's avatar

arghhh now I'm getting: "message": "Too few arguments to function Illuminate\Support\Collection::get(), 0 passed in /Users/myname/playground/appname/app/Modules/Transaction/Controllers/TransactionController.php on line 157 and at least 1 expected",

line157:

foreach ($commentService->getTransactionComments()->get() as $comment) {
Zain_Zulifqar's avatar
public function getTransactionComments()
{
    $query = Comment::query();
    
    $comments = $query->with(['payment','club'])
			->orderBy('created_at', 'ASC');
																																											
    
    return $comments->get();
}
1 like

Please or to participate in this conversation.