Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent

I get class Page not found when I try to retrieve a field from Page. So on $section->sectionable->title

<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Section extends Model { protected $table = 'sections'; protected $fillable = ['name','description','slug','section_type','status']; protected $hidden = ['id' , 'deleted_at']; public function sectionable() { return $this->morphTo(); } } class Page extends Model { protected $table = 'pages'; protected $fillable = ['title','body','slug','status','meta_title','meta_description','meta_keywords']; public function author() { return $this->belongsTo('App\Models\User', 'user_id'); } public function sections() { return $this->morphMany('App\Models\Section', 'sectionable'); } }
Last updated 3 years ago.
0

I came across the same problem above. Is there any solution or workaround to this one?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

maxi032 maxi032 Joined 26 Apr 2014

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.