Support the ongoing development of Laravel.io →
Requests Architecture
Last updated 2 years ago.
0

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.

Last updated 9 years ago.
0

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/

Last updated 9 years ago.
0

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?

0
Solution

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.

Last updated 9 years ago.
0

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

0

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 
   }
}

Last updated 9 years ago.
0

Okay, thanks for the help :) Looks logic to me. Helped a lot :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

LukasMa lukasma Joined 26 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.