Closed faidoc closed 10 years ago
Hi faidoc!
Hum, are you sure you have mongoDB installed? if not: http://www.mongodb.org/downloads
Or, maybe try removing these lines at the beginning of you model classes:
use Jenssegers\Mongodb\Model as Eloquent;
another ideas: http://docs.mongodb.org/ecosystem/drivers/php/
Please, let me know how you fixed it when you do!
Yep, I commented those lines and it works. Now the only problem I see is with the /users/{users}/show route
I'm doing for example after registering the first user:
First I log in with the user in /users/auth Then, try this other: /users/0/show but I end up with the error
{"error":{"code":500,"message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.id' in 'where clause' (SQL: select * from
userswhere
users.
deleted_atis null and
users.
id= 0 limit 1)","file":"\/home\/vagrant\/Code\/prueba.com\/vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connection.php","line":625}}
The error says it can not find the column users.id and the correct name as I can see it on the database is _id. Where can I correct that column name? I can't find it on the models...
Thanks
Hum.. i think laravel eloquent use by default the id as primary key in the db. I think there is a way to force using it with _id. Probably specifying a parameter in the model. You may have some doc about it on the official doc. I mainly tested the api with mongodb so my code may have a few glitches like this.. sorry :s
Yes, thanks, I searched for that and found that I can do:
protected $primaryKey = '_id';
on the Users model.
Now... I promise... last question xD... I get that there's no token for /users/0/show when theres a user with _id 0 and a token where the user_id is 0
What do you think is wrong now?
Thank you and sorry xD
No worries. Usually with mysql, primary keys start at index 1. Have a look in your db.
Thanks
Ok I saw that the migration didn't put the _id autoincremental so I made some changes because it was failing when creating a second user. Changed it to autoincremental and put the first user as 1.
Now I know there's the token for the user when I log in. I post with postman and get status 202 accepted.
But with /users/1/show it keeps saying there's no token.
To make sure I'm doing it right in postman, I do this with the basic Auth tab, where I put the email and password I put when registering the user, this gives me the authorization header that I put like:
Authorization Basic ZmFpZG9jQGdtYWlsLmNvbTp0aWNrZXQ=
And execute the GET in /users/1/show
I get status 401 Unauthorized... -.-
Finally got it -.-
The request had to be with a URL parameter with the token received when you log in right?
For example:
http://test.com/v1/users/1/show?token=N2tFeUwwZWE5OGhRQkJTTFFuZklaRVZ5eFBWVEFSZUhtaUh0WlNWZz0=
That way it shows the session.
Thanks for your help trying to figure it out all these things
Hello, this looks very promising, looking for a solution like this for hours now!
Could you have time to make a new version just for mysql?
Thx, I'll try to find a moment this week-end..
Merlosy, I am working on a solution that requires data access control based on roles. Would you be interested in adding starter code for that functionality to the project?
Hi kwab, why not.. Can you open a new issue for that? I'd rather keep things organized as this issue will be solved soon.
Do you already have some code about it?
Thx
Hi
Thanks for sharing this code.
I have in mind using it but with mysql. I have everything in place and I've edited database.php to default to mysql. But when I do post to users to create a new one I get:
{"error":{"code":500,"message":"Class 'MongoDate' not found","file":"\/home\/vagrant\/Code\/prueba.com\/vendor\/jenssegers\/mongodb\/src\/Jenssegers\/Mongodb\/Model.php","line":212}}
What am I missing to use this code with just mysql?
Thanks