Do you know basic database design? Are you already pretty good at php? There are some laracast on crud.
Are you trying to show users there own data? Sounds like you need to have a section for admins separate, and a users area where a user can view their own data only. This can be done with the users login info, and linked tables.
https://www.youtube.com/results?search_query=laravel+crud
There are severl fine videos.
I think you are slightly mixing up the term of CRUD and REST. Surely they do have a lot of similarity. :D
This post might help. http://programmers.stackexchange.com/questions/120716/difference-between-rest-and-crud
CRUD normally refers to the common operations of data. Your Eloquent should already provide you this functionality out of the box when you install Laravel.
Now, to archive what you meant "CRUD" but actually a RESTful services,
You might need to consider applying some resources, or even logic to abstract your data and present them to your user via a URL and HTTP methods.
For example, in your case, showing user his folders and files in your URL like, users/Tom/files/
Thanks for the link, I will take a look. Since I created this post I converted my User ressource to be RESTful or CRUDful or whatever ^^
awsp said:
For example, in your case, showing user his folders and files in your URL like,
users/Tom/files/
This is basiclly what I wanted to know. I watched this laracast, which cleared some of my questions: https://laracasts.com/lessons/understanding-rest So it's not a bad "style" if I call "users/Tom/files" and return my files AND folders?
To my understanding, a folder is a place where a bunch of files fit in, so these files should also be considered files, isn't it? :D
Unless you don't want to get all your "files" recursively but to the existing directory level only ...
It does make sense to me that you have folders and files in this URL. /users/Tom/files
As long as your user get what they are supposed to get and if that is the way you make your REST API available for CRUDing data to Internet users.
I think it is totally fine.
Thanks, that helped me a lot :)
One last question ^^ I have a admin section. It can manage all users in a RESTful way (I mentioned that above). But what if a user wants to change his own data/profile? What would be the workflow? Implementing a check in the Users controller if the request is from and admin or user and then show different views for everyone?
Thanks
Not sure if I understand it totally,
/users/Tom/files
looks like a nested resource to me, so eventually you would have something like,
UserFileController
when you are dealing with the actually user Tom, it looks natural to me you would have something like,
UserController
or
UserProfileController
depending on how you construct your database schema.
If you are doing UserController, I would assume you have the deal with UserModel. In this case you call your repository / model and do whatever you need to do.
If you are doing UserProfileController, I would assume you are dealing with something like this, http://laravel.com/docs/4.2/controllers#restful-resource-controllers
class UserProfileController {
// GET users/Tom/profile
public function index ($userId)
{
// find the user with this name, (you could also use ID instead)
// showing a user's profile
}
// PUT users/Tom/profile
public function update($userId)
{
// find the user with this name, (you could also use ID instead)
// get this person's profile
// update this user's profile
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community