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 !!'); }
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community