's belongsto or hasOne how to get data from linked table?

Stuck can't move forward, explain to me please:

There are two table Areas(structure id, district) and Ads(structure id, district_id, text)

Conventionally, in the controller, write the following Ads:
public function allads(){
$adsall=Ads::orderBy('id','desc')->paginate(10);
 return view('test2', compact('adsall'));
 }


The output in the view have the array $adsall with all the ads and with the help of this design we have {{$ads->district_id}} . How to display not the ID of the district and his real name from the second table when checking with a field district_id?
March 23rd 20 at 19:40
1 answer
March 23rd 20 at 19:42
Solution
class District extends Model {
 public function ads () {
$this->hasMany(Ad::class);
}
}

class Ad extends Model {
 public function district () {
 $this->'s belongsto(District ::class);
}
}

$adsall = Ad::with(['district'])->latest()->paginate(10);
get the error
Call to a member function addEagerConstraints() on null - darren92 commented on March 23rd 20 at 19:45
return all figured out I forgot to specify - darren92 commented on March 23rd 20 at 19:48

Find more questions by tags Laravel