Relation between one table records [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have a User table.Some Users have a manager which is a user too.
I need one to many relationship between users, but I don't want to create a new table for that.
I can use manager_id to relate users to their manager.
Now my question
Is it a right way to do some thing like that? If no, so what's the best way?
I'm using laravel and sqlite, relation is one to many

In the User table, you can add manager_id. This will create parent to child relationship. It will also support multiple hierarchies where managers can also have managers.
I have used this same model on categories which have sub categories.
This will work

Related

store users in one table or multiple table Laravel [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 21 hours ago.
Improve this question
we are creating an e-learning website with Laravel, and we have multiple users (student, instructor, admin) should we store them in one table (users) or each user with own table.
I want to know if there is a convention
There is no set in stone rule, it is totally up to you. But from what I see in most Laravel projects, and what I do in my projects as well, to make it easier to read/troubleshoot you use a single "users" table and make a "profile" or "profile_type" column to determine which one are they attached to.

PHP & MYSQL tables [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to figure it out this simple issue. I have two tables
1) Services
2) Projects
Some projects are using only one service_id (ex: web dev), but other are connected with two or three of them (ex: web dev, branding) and I have only one table call service_id. How can I add more than just one service_id?
Services
Projects
Like #ccKep wait, you need to create a table to link Services with Projects. So your database structure would look like:
You can then combine as many services to as many projects as you want. Projects_has_Services contains pairs of (service_id, project_id).

Laravel relationship count [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I know title seems a little complicated, but what I want is simple
Users (users) have comments (comments)
To fetch users' comments, I'm using a hasMany relationship
I'm creating a filter system, so I only want to fetch users who have posted at least 1 comment
Use has():
$users = User::has('comments')->get();
Or eager load the users comment models:
$users = User::has('comments')->with('comments')->get();
Source: http://laravel.com/docs/eloquent#querying-relations

retrieving a row using laravel eloquent ORM [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to get back single row where a user just added a new car. I am trying to join all tables using the eloquent ORM. here is a erd of my database I am new to laravel, and I would want to know how I would be able to achieve this. Thanks in advance.
What have you tried already?
Assuming you want to get latest added Car model, you could do
$latestCar = Car::orderBy('id', 'DESC')->first();
If you have nothing yet, you could watch Laracasts about how to build a database and set up Models.

Where to put a method? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I've one question.
I'm currently having two classes:
A class called RoomFactory, which builds Room Objects and a class called User.
A User can own Rooms.
Now I wanted to get the Rooms of a User. But where do I put the method?
I could put the method in RoomFactory and call it GetRoomsOfUser($UserObject), I could put the method in the User Object and call it GetRooms() or I could put it in both.
What would be the best practice for this?
It should live on the User object. The job of the RoomFactory is to build Room objects, not to fetch User-related objects.

Categories