I have a question about dynamic properties in Laravel 4.
First, look at this view.blade.php
file
@extends('layouts.master')
@section('content')
League: {{$league->name}}
Teams:
@foreach($league->teams as $t)
{{$t->name}}
@endforeach
@stop
This is a normal case of dynamic property usage I assume.
In my machine, the file return an error: the foreach is supplied with invalid argument $league->teams
is simply int(0)
.
But when I use $league->teams()->get()
it's working as intended.
Also when I use $league->tEams
it's working too, please note the capital E.
I have added a github repo at https://github.com/joturako/d2tm
, anyone is kind enough to explore this problem can do so.
I believe this either is a bug with laravel itself, or a combination of laravel,windows 8 and xampp i'm using; or it is just my incomplete knowlegde about everything.
Anyway, thanks for reading my question and hope someone can enlighten me.
You have the two models belonging to each other, the relationship in Team should be
public function leagues() {
return $this->hasMany('League');
}
Then $league->teams should retrieve the teams list.
ok it's not anyone fault, it's my fault. i have a field named teams
in the Leagues
table. That explain why...
I feel dumb now, hope somebody can delete this question for me.