mardi 7 février 2017

Laravel hasMany Relationship error Undefined property

Vote count: 0

I am trying to return all media that I have linked to a device via the database. I had this working in an older version of laravel but now on the most recent verion I have copied and pasted the code over and I am getting an error.

I run a schedule and each schedule has media linked to it.

Model:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Schedule extends Model
{
    //
    public function scheduled_media(){

        return $this->hasMany('App\ScheduledMedia');

    }
}

Blade:

@foreach($schedule->scheduled_media as $m))
    
@endforeach

Error:

Undefined property: stdClass::$scheduled_media (View: C:\xampp\htdocs\displaycontroller\resources\views\sites\showdisplay.blade.php)

I am lost as I dont understand why it is saying that it is an undefined property when I have it written in the Model as you can see above.

Thanks,

D

asked 8 secs ago

Let's block ads! (Why?)



Laravel hasMany Relationship error Undefined property

Aucun commentaire:

Enregistrer un commentaire