Hi I am a beginner at laravel, I have two tables and i want to show a description related to the name and I have already made the relation from the model but How to fetch data related to the name please help me thanks.
Model Facility
class Facility extends Model
{
protected $table="sm_facilities";
protected $guarded = ['id','created_at','updated_at'];
public function categories()
{
return $this->hasMany('App\FacilityCategory','mf_facility_category_id','id');
}
}
示范设施类别
class FacilityCategory extends Model
{
protected $table = 'mf_facilities_categories';
public function facilities()
{
return $this->hasMany('App\Facility','mf_facility_category_id','id');
}
控制者
class FacilityController extends Controller
{
public function index()
{
$data=[
'facility'=>Facility::with('categories')->where('status',1)->get()
];
return view('facility');
}
}
you can have
one-to-one
relationship