Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

johnDoe220's avatar

Help to make tables for the project

I have a table named cars in which the list of cars is specified. The next table is details, which includes car details such as mirrors, rims, tires, and all of these are created separately in the name column. Now what I have been asked is this. There is a form that includes: 1- It is the name of the details (mirrors, rims, etc.). 2- A check box that contains a details link 3- An input to explain each detail 4- The name of the driver as a string 5- ID of the manager, visitor, supervisor or... when registering the visit. It should be noted that each car can have unlimited visits. Since the driver is unknown, it must be entered as a string. On the other hand, every visit and registration that is done should be displayed as a list in the form of a table, which in my opinion can be done with the created_at field.

0 likes
1 reply
LaryAI's avatar
Level 58

Based on the question description, it seems like you need to create a new table to store the details of each visit made by a driver for a particular car. Here's an example schema for the new table:

visits
- id (primary key)
- car_id (foreign key to cars table)
- detail_name (string)
- detail_link (boolean)
- detail_description (text)
- driver_name (string)
- manager_id (foreign key to managers table)
- visitor_id (foreign key to visitors table)
- supervisor_id (foreign key to supervisors table)
- created_at (timestamp)

You can then use Laravel's Eloquent ORM to define relationships between the tables and retrieve the data as needed. Here's an example of how you can retrieve all visits for a particular car:

// In Car model
public function visits()
{
    return $this->hasMany(Visit::class);
}

// In controller
$car = Car::find($carId);
$visits = $car->visits;

You can then loop through the $visits variable in your view to display the data in a table.

Please or to participate in this conversation.