我有以下途徑:模型關係和路線得到模型ID
Route::get('notes/main', function(){
$destinations = Destination::where('show', '=','1')->get();
$notes = Destination::find($destination->id)->notes()->get();
return View::make('notes.main')
->with('destinations', $destinations);
});
//關係模型:
<?php
class Destination extends Eloquent {
public function notes()
{
return $this->has_many('Note');
}
}
<?php
class Note extends Eloquent
{
public function destination()
{
return $this->belongs_to('Destination');
}
}
//查看:
@foreach($destinations as $destination)
{{ $destination->name}}<br>
{ $notes->destination->text }} // this isn't echoed
@endforeach
什麼是正確的方式來過濾這個並定義$ destination-> id
謝謝
我將如何篩選循環內if語句中的註釋? @if(isset($注意 - >稱號)!= 'shorttext')
@else
<p> {{ $note->text }} </p>
@endif
@endforeach
我得到:未定義的變量:目的地 – dflow