私は、フォーラムユーザーのために、基本的に彼らがゲームに勝つと思う人に入ることができ、その後結果が来ると、インハウスのスポーツページを幾分設定しようとしました彼らが正しければポイントを与えられます。関係が正しいユーザーデータをもたらすラベール関係
これを実行しているうちに問題が発生しました。これまでのところ、私はデータベースにゲームを持っていて、Resultsリレーションを作成しました。 問題は、ユーザーが前記の日付(いくつかのイベント)ですべてのゲームを表示しているときに、関係がそのユーザーに属するものを知らないということです。私は今、数時間試しましたが、正直に空白を描いています。これを見てください:
ルート:
Route::get('/event/{date}/list', 'Other\[email protected]');
コントローラー:
public function indexDateGames($date)
{
$dateToday = (new \DateTime())->format('Y-m-d H:i:s');
$events = Event::where('date', $date)->get();
$uid = Auth::user()->id;
$vars['uid'] = $uid;
$vars['date'] = $date;
$vars['dateToday'] = $dateToday;
$vars['events'] = $events;
if ($date >= $dateToday) {
$vars['url'] = 'eventsUpcoming';
} else {
$vars['url'] = 'eventsPassed';
}
return view('other.event_on_date', $vars);
}
モデルの結果:
public function event()
{
return $this->belongsTo(Event::class);
}
モデルイベント:
public function result()
{
return $this->hasOne(Result::class);
}
ビュー:関係は基本的に 「$ event->結果は」実際にあなたの結果であることを知っているように、
<div class="row">
<div class="col-lg-6">
<div id="spinner" style="margin-top:200px;margin-left:47%;">
<i class="fa fa-spinner fa-spin fa-5x fa-fw"></i>
</div>
<div id="data" style="display:none;margin:10px;">
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Tid</th>
<th>Resultat</th>
<th>Ditt val</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Tid</th>
<th>Resultat</th>
<th>Ditt val</th>
</tr>
</tfoot>
<tbody>
@foreach($events as $event)
@if ('2017-09-16 16:00:00' < $event->start)
<tr>
<td>{{$event->start->format('H:i')}}</td>
<td>
@if (isset($event->result->result))
@if ($event->result->result == 1)
<a href="#" class="btn btn-success btn-xs" role="button" aria-pressed="true">{{$event->home}}</a>
<a href="{{ URL::to('/event/' . $event->id . '/changeresult/2/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">X</a>
<a href="{{ URL::to('/event/' . $event->id . '/changeresult/3/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">{{$event->away}}</a>
@elseif ($event->result->result == 2)
<a href="{{ URL::to('/event/' . $event->id . '/changeresult/1/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">{{$event->home}}</a>
<a href="{{ URL::to('#') }}" class="btn btn-success btn-xs" role="button" aria-pressed="true">X</a>
<a href="{{ URL::to('/event/' . $event->id . '/changeresult/3/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">{{$event->away}}</a>
@elseif ($event->result->result == 3)
<a href="{{ URL::to('/event/' . $event->id . '/changeresult/1/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">{{$event->home}}</a>
<a href="{{ URL::to('/event/' . $event->id . '/changeresult/2/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">X</a>
<a href="{{ URL::to('#') }}" class="btn btn-success btn-xs" role="button" aria-pressed="true">{{$event->away}}</a>
@endif
@else
<a href="{{ URL::to('/event/' . $event->id . '/result/1/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">{{$event->home}}</a>
<a href="{{ URL::to('/event/' . $event->id . '/result/2/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">X</a>
<a href="{{ URL::to('/event/' . $event->id . '/result/3/' . $uid) }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">{{$event->away}}</a>
@endif
</td>
@elseif (isset($event->final_result))
<tr>
<td>{{$event->start->format('H:i')}}</td>
<td>
@if ($event->final_result == 1)
<a href="{{ URL::to('#') }}" class="btn btn-success btn-xs" role="button" aria-pressed="true">{{$event->home}} vann matchen över {{$event->away}}</a>
@elseif ($event->final_result == 2)
<a href="{{ URL::to('#') }}" class="btn btn-success btn-xs" role="button" aria-pressed="true">Matchen slutade lika mellan {{$event->home}} och {{$event->away}}</a>
@elseif ($event->final_result == 3)
<a href="{{ URL::to('#') }}" class="btn btn-success btn-xs" role="button" aria-pressed="true">{{$event->away}} vann matchen över {{$event->home}}</a>
@endif
</td>
@else
<tr>
<td>{{$event->start->format('H:i')}}</td>
<td>
<a href="{{ URL::to('#') }}" class="btn btn-danger btn-xs" role="button" aria-pressed="true">Matchen låst - Resultat ej fastställt</a>
</td>
@endif
@if (isset($event->result->result))
<td>
@if ($event->result->result == 1)
<a href="{{ URL::to('#') }}" class="btn btn-success btn-xs" role="button" aria-pressed="true">{{$event->home}}</a>
@elseif ($event->result->result == 2)
<a href="{{ URL::to('#') }}" class="btn btn-success btn-xs" role="button" aria-pressed="true">Lika</a>
@elseif ($event->result->result == 3)
<a href="{{ URL::to('#') }}" class="btn btn-success btn-xs" role="button" aria-pressed="true">{{$event->away}}</a>
@endif
</td>
</tr>
@else
<td>
<a href="{{ URL::to('#' . $event->id . '/result/1') }}" class="btn btn-default btn-xs" role="button" aria-pressed="true">Inget val gjort</a>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
</div>
</div>
誰がそれを作る方法を知っていますか?私はこのdoesntの仕事を知っているが、これはあくまでも一例です:
$event->result(WhereUserId($uid)->result
のhttp://をi.imgur.com/UtFEFPc.png これはビューの外観です。 – Stoff
ユーザーとイベントの間のrerlationshipは何ですか? – Maraboc
基本的にそれらの間には全く関係がありません。すべて同じイベントにアクセスできる50人のユーザーがいます。それはユーザーによってユニークな結果です。それが意味をなさないかどうかはわかりません。このイベントは、現在ゲームがあるときを表示する方法に過ぎず、ゲームの種類に基づいて結果を作成します。 – Stoff