Support the ongoing development of Laravel.io →
Input Laravel Database

I have 3 tables called country,city,university

the country and city value displayed as dependent with each other now i want to put the university according to country and city in university table

country model-> protected $table = 'countries_tbl'; protected $primaryKey = 'id'; protected $fillable = ['name'];

public function cities() {
    return $this->hasMany(RegionModel::class);
}

city model->

protected $table = 'region_tbl';
protected $primaryKey = 'id';
protected $fk		='country_id';
protected $fillable = ['name'];

public function country(){
	return $this->belongsTo(CountryModel::class);
}
public function university() {
    return $this->hasMany(UniversityModel::class);
}

university model-> protected $table = 'university_info_tbl'; protected $primaryKey = 'id'; protected $fillable = ['name','university_id','region_id','university_address','university_short_descr','university_cover_img','university_logo_img','world_ranking',' acceptance_rate','avg_tuition_fees',' overview','admission_requirements,'];

public function product() {
          return $this->belongsTo(RegionModel::class);

}

Controller:

$university_add = new UniversityModel; $university_add->name= $request->input('name'); $save = $university_add->save(); if ($save) { return redirect()->back()->with('success', 'Save Successfully !!'); }

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Arman rajucs Joined 24 Jul 2018

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.

© 2025 Laravel.io - All rights reserved.