City
id, name, user_id
Area
id, name, city_id, user_id
Neigborhood
id, name , area_id, user_id
Street
id, name, neigborhood_id, user_id
People
id, name, etc
Would this be a good way to link everything together?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
As i just started with laravel after not seeing any php for many years, i wanted to get on the forum and ask for some advice. Seeing this will be multiple joins and needs a good DB structure. Below are the relations.
Many Street -> Neighborhood
4 Neighborhoods -> Area
7 Area's -> City
Out of the users table
1 Person = Responsible for a Neighborhood
1 Person = Responsible for a Area
1 Person = Responsible for a City
There will be a search form. where you can select to search for people / Streets when it found the "LIKE" it should output the information that is linked to the person or street. for instance i look for Person A. which is responsible for Neighborhood A. and has a person above him that is Responsible for Area A.
Maybe someone could be so kind to get me a little started on the database to make it efficient.
I would go with this approach.
Street table and modelNeighborhood table and model.Area table and model.City table and model.Each of them will have a unique ID, in their migrations, they'll have this which will be their unique ID and primary key. The migrations will look like this:
//street_migration
<?php
.
.
.
Schema::create('street', function (Blueprint $table) {
$table->increments('id');
$table->name('name');
$table->integer('neighborhood_id');
});
//neighborhood_migration
<?php
.
.
.
Schema::create('neighborhood', function (Blueprint $table) {
$table->increments('id');
$table->name('name');
$table->integer('area_id');
$table->integer('user_id')->unsigned();
});
//area_migration
<?php
.
.
.
Schema::create('area', function (Blueprint $table) {
$table->increments('id');
$table->name('name');
$table->integer('city_id');
$table->integer('user_id')->unsigned();
});
//city_migration
<?php
.
.
.
Schema::create('city', function (Blueprint $table) {
$table->increments('id');
$table->name('name');
$table->integer('user_id')->unsigned();
});
You can as well implement foreign keys if you need one.
Now, I will proceed to add relationships in the models, I believe a Street can only belong to one Neighborhood.
So in the Street model, I have this:
<?php
//App\Street
.
.
.
public function neighborhood(){
return $this->belongsTo('App\Neighborhood');
}
While in the Neighborhood, a Neighborhood can only belong to one Area but have many Street and also be assigned to a User.
<?php
//App\Neighborhood
.
.
.
public function streets(){
return $this->hasMany('App\Street');
}
public function area(){
return $this->belongsTo('App\Area');
}
public function user(){
return $this->belongsTo('App\User');
}
An Area can have many Neighborhood but can only belong to one City and also be assigned to a User
So in the Area model, I have this:
<?php
//App\Area
.
.
.
public function neighborhoods(){
return $this->hasMany('App\Neighborhood');
}
public function city(){
return $this->belongsTo('App\City');
}
public function user(){
return $this->belongsTo('App\User');
}
Lastly, a City can have many Area and only belong to a User, so we have this in the City model:
<?php
//App\City
.
.
.
public function areas(){
return $this->belongsTo('App\Area');
}
public function user(){
return $this->belongsTo('App\User');
}
Finally, for the User, we already have a user_id field for Neighborhood, City and Area and a relationship for each of them from those models. To access a User area, neighborhood or city, we add this to the User model:
<?php
//App\User
.
.
.
public function neighborhood(){
return $this->hasOne('App\Neighborhood');
}
public function area(){
return $this->hasOne('App\Area');
}
public function city(){
return $this->hasOne('App\City');
}
That, my friend is how you implement something like what you desire.
Please or to participate in this conversation.