Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

577
Views
Laravel Call to undefined method HasMany::mapInto() when requesting data

I am getting a strange error which I cannot work out.

I have a User and also a Partner model. A user can have multiple partners. I am trying to retrieve a list of partners that the user has. I am also using Laravel Sanctum as my auth guard.

My relationship code is as follows;

In my user model

public function partners(): HasMany
{
    return $this->hasMany(Partner::class);
}

In my Partner model

public function user(): BelongsTo
{
    return $this->belongsTo(User::class);
}

My route definition looks like so;

Route::middleware(['auth:sanctum'])->group(function () {
    Route::apiResource('partners', Api\Partner\PartnerController::class)
    ->only(['index']);
});

and finally in my controller;

public function index(Request $request)
{
    return PartnerResource::collection($request->user()->partners());
}

When I hit the endpoint though, I am getting the following error;

Call to undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::mapInto()

I cant figure out the issue. Any insight would be greatly appreciated.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When You are Calling user()->partners() it returns Illuminate\Database\Eloquent\Relations\HasMany Instance.

Resource needs to get Illuminate\Database\Eloquent\Collection Instance.

You have to just call user()->partners ( Remove parenthesis )

Or call get method on Illuminate\Database\Eloquent\Relations\HasMany Instance, to get Collection

user()->partners()->get()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!