1

I get the following error when adding to the command line like this:

error: Call to undefined method Illuminate\Database\Eloquent\Builder::mapInto()

This is my code: enter image description here

If i leave out the command line Project::where('user_id', auth()->user()->id) go and replace it with the command line Project::all() everything works fine but i want to get the list of projects belonging to a certain user then i have to use the other command this makes me almost like i can't find a way to deal with it.

Error message: enter image description here

I have consulted the following post to be able to retrieve by user_id: I have an idea to use auth middleware to retrieve a user's products

Atika
  • 1,025
  • 2
  • 6
  • 17
  • Have you viewed this content https://stackoverflow.com/questions/47710805/laravel-api-resource-call-to-undefined-method-illuminate-database-query-builder – nrkdrk Aug 16 '21 at 08:46
  • 1
    I tried this it seems it didn't work in my project. Finally, thank you for suggesting to help me – Bình Nguyễn Aug 16 '21 at 09:06

1 Answers1

0

Since the Eloquent model acts as a query builder, you can add additional constraints to the queries and then call the get method to get the results.

Other methods :

  • all
  • get
  • first

For Laravel Eloquent => https://laravel.com/docs/8.x/eloquent

I think this might be the right solution for you :

project::Where('user_id',auth()->user()->id)->get();
Atika
  • 1,025
  • 2
  • 6
  • 17
nrkdrk
  • 78
  • 9