#No query results for model [AppModelsUser] me

1 messages · Page 1 of 1 (latest)

main sundial
#

I'd suggest having a look at OAuth and passport again. You are going against everything you are supposed to be doing.

abstract urchin
main sundial
#

Sure thing bud. That will take you far.

#

OAuth aside, taking one request to dispatch it internally to another controller is such an antipattern.

abstract urchin
blazing canyon
abstract urchin
#

even if this is a bad practise, i shouldnt get 404 from users/me

blazing canyon
#

Also, the #rules state not to post screenshots but to post code instead.

abstract urchin
#

route:list is showing me that endpoint

#

kinda weird to get 404 not found

#

like it doesnt even exist 🤔

blazing canyon
#

@abstract urchin The error is saying you’re trying to query your user model with an ID of “me”, which suggests you have another route taking precedence that looks a user up by ID.

abstract urchin
#

lol

#

lol

#

is it that simple

main sundial
#

Just my observation, but if you indeed got that from uni, then that worries me. I can understand not knowing that the password grant type has been considered bad practice and should be phased out. But on top of that, you are

  • Using emv() helper outside of your configuration files

https://laravel.com/docs/9.x/configuration#configuration-caching
If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded; therefore, the env function will only return external, system level environment variables.

  • overwriting the request to dispatch to an internal route
  • OAuth and "logout" do not go together
abstract urchin
#

yeah ive got users/{id} and users/me

#

hmm however ive got users/chef and users/manager and it is working

#

nah it is not that

#

ive deleted every endpoint about users

#

i didnt work...

blazing canyon
#

So show what error you’re getting.

abstract urchin
#

the same error

blazing canyon
#

You’re not sending a JSON request properly.

#

So you’re just getting a HTML response and I have no idea what the error is, but it’s not the “same” as before.

abstract urchin
#

it is the same, i was just showing the erro from console/postman

#

but inside network tab, i still have the same error message

blazing canyon
#

You’re still trying to query a user model with a primary key of “me”

abstract urchin
#

ik this is laravel discord, but im using axios on vue (frontend)

blazing canyon
#

That doesn’t change what I’ve said twice now?

abstract urchin
#

const response = await axios.get('users/me')

blazing canyon
#

The problem is server side. Has nothing to do with Axios or anything else about your JavaScript.

abstract urchin
#

can you more clear about the error?

#

what can be causing it?

#

why it is looking for "me" as id

blazing canyon
#

You need to actually work out which controller action is being hit.

abstract urchin
#

the endpoint is well defined inside api.php

#

and the controller is associated to it

#

route:list shows that as well

blazing canyon
#

And what’s that got to do with what I’ve just suggested?

abstract urchin
#

ive got no clue on what youve just suggested

blazing canyon
#

I’ve just suggested you actually need to verify what controller action is responding to the request.

#

Instead of just guessing or assuming.

abstract urchin
#

no its not

blazing canyon
#

Because it clearly isn’t the action you think it is.

abstract urchin
#

ive already did that

#

i tried to return a response with a msg and status code

#

and it didnt do nothing, so it isnt calling that endpoint

blazing canyon
#

abstract urchin
#

however i cant understand why it isnt calling it

blazing canyon
#

You’ve already been told: you have another route taking precedence.

abstract urchin
#

ive commented all the routes

#

i only have 3 routes uncommented

blazing canyon
#

And?

abstract urchin
#

middleware auth:api group function, login, logout and users/me

blazing canyon
#

And?

#

You. Still. Need. To. Verify. Which. Controller. Action. Is. Actually. Handling. The. Request.

#

You’re just shooting in the dark and then acting confused why you’re not hitting anything.

abstract urchin
blazing canyon
#

Because you keep getting told the same thing multiple times yet want to give me unrelated information and answers to questions I haven’t asked.

#

You have a route responding to that request. Use php artisan route:list --path=api/users to get a list of candidates.

abstract urchin
blazing canyon
#

So look at all those routes, including the ones that take an ID…

#

You also seem to be caching routes. Don’t.

#

Delete your route cache, and never run in development again.

abstract urchin
blazing canyon
#

I don’t know because you still haven’t identified which one is actually handling the request.

lament jasper
#

I know it is an old post , but I was getting the same error when building an API and didn't found anywhere. I know a possible solution and explanation about this. I'm posting here because maybe someday someone will take a look at this post having the same problem. Did you solve the problem @abstract urchin ?

#

The problem is that you have two or more routes with the same name, for example:

GET|HEAD api/users/delivery
GET|HEAD api/users/me
GET|HEAD api/users/{id}

What happens is that when laravel builds the route api/users/{îd}, anything can be sent to {id} portion, so it could be 123 or yadayada. So, whenever a request is made for api/users/me or api/users/delivery, laravel thinks it is for api/users/{id}, and then tries to load the model.
I had the same error happening and was losing my mind on it, and it was simple. If there wasn't the route api/users/{id} then laravel can read both api/users/me and api/users/delivery correctly.
I hope it helps anyone seeing this.

cinder jacinth
#

The simplest solution to this would be:

Route::get('users/{id}', ['UserController', 'show'])->where('id', '[0-9]+');