2017-02-16 2 views
0

Ich habe Laravel mit Mongodb und Inside Sammlung Dokument wie folgt;Laravel, Mongo, @foreach Logik in Sicht

}, 
     "et_score": null, 
     "starting_time": "13:00:00", 
     "competition": { 
      "active": true, 
      "id": NumberInt("46"), 
      "name": "Liga 1" 
     }, 
     "awayTeam": { 
      "venue_id": NumberInt("2454"), 
      "name": "Team away -> Liga1", 
      "coach_id": NumberInt("140772"), 
      "twitter": "" 
     }, 
     "homeTeam": { 
      "venue_id": NumberInt("0"), 
      "name": "Team home -> Liga1", 

     }, 
     "home_score": NumberInt("1"), 
     "starting_date": "2016-12-24", 
     "away_score": NumberInt("1") 
    } 
}) 

.....

Und mein .blade hat dies;

.... 
    @foreach($data_user as $league) 

     <table class='table table-striped table-bordered table-condensed'> 

     <thead><tr><th>{{$league{"competition.name"} }}</th></tr></thead> 
      @endforeach 

     <tbody> 
      <tr> 
       @foreach($data_user as $match) 


        <th>{{$match{"starting_date"} }}</th> 
        <th>{{$match{"starting_time"} }}</th> 
        <th>{{$match{"status"} }}</th> 
        <th>{{$match{"homeTeam.name"} }}</th> 
        <th>{{$match{"home_score"} }} : {{$match{"away_score"} }} </th> 
        <th>{{$match{"awayTeam.name"} }}</th> 
      </tr> 
      @endforeach 
     </tbody> 
     </table> 
..... 

Diese Tabelle ausdrucken wie diese;

table.jpg

Wie Sie sehen, ich habe alle Teams in einem "luega Tisch" und Team zuteilen würde "Team Home -> Liga1" zu Tisch Liga1 gehen und auch "Team Home -> Super League" sollte sein in Super usw.

ich weiß, dass ich eine gewisse Logik in @foreach fehlt, aber ich habe nicht genug Erfahrung für eine solche Sache zu beheben, Danke

Antwort

0

ich nicht genau verstehen, was Sie tun wollen, aber von dem, was ich sehe, öffnen oder schließen sie ihre foreach falsch, das generiert schlecht die html, neben der schlechten nutzung des modells.

Überprüfen Sie die folgenden

@foreach($data_user as $league) 
<table class='table table-striped table-bordered table-condensed'> 
    <thead> 
     <tr> 
      <th>{{$league->competition->name }}</th> 
     </tr> 
    </thead> 
    <tbody> 
     @foreach($data_user as $match) 
     <tr> 
      <th>{{$match->starting_date }}</th> 
      <th>{{$match->starting_time }}</th> 
      <th>{{$match->status }}</th> 
      <th>{{$match->homeTeam.name }}</th> 
      <th>{{$match->home_score }} : {{ $match->away_score }} </th> 
      <th>{{$match->awayTeam.name }}</th> 
     </tr> 
     @endforeach 
    </tbody> 
</table> 
@endforeach 
+0

Hallo Manuel, Fehler mit Ihrem Vorschlag erhält: Versuchen auf Linie Eigenschaft von nicht-Objekt zu erhalten 4 – Ronnin

+0

Die Informationen, die ein Ergebnis des Modells ist, eine Sammlung, ein Array ? Überprüfen Sie das, oder fügen Sie weitere Informationen hinzu, um Ihnen zu helfen, aber denken Sie daran, dass Sie foreach falsch schließen und HTML mit Fehlern generieren –

+0

ErrorException in f1da8afe98aba2781763f1e975725bb2aaa771cf.php Zeile 5: Der Versuch, die Eigenschaft non-object zu erhalten, die Eigenschaft non-object (View: /Volumes/WEB/test/CRUD-Laravel-5.3-with-MongoDB/resources/views/myhome.blade.php) – Ronnin

0

Vielleicht, wenn mehr Hilfe, wenn Sie sehen, Modell und Controller

Modell:

<?php 

namespace App\Models; 

use Moloquent; 

class PrimaryModels extends Moloquent 
{ 
    protected $collection = 'football.live'; 
} 

Controller:

<?php 

namespace App\Http\Controllers; 

use App\Models\PrimaryModels as Moloquent; 
use Illuminate\Http\Request; 
use Input, Redirect; 

class PrimaryController2 extends Controller 
{ 
    function index(){ 
     return Redirect::to('myhome'); 
    } 

    function pages($template){ 
     $getAllData = Moloquent::all(); 
     return view($template, ['data_user' => $getAllData]); 
    } 

} 
0

Aber wenn ich gehen So habe ich s am prob, dass alle Teams in allen Ligen sind

@foreach($data_user as $league) 
    <table class='table table-striped table-bordered table-condensed'> 
     <thead> 
     <tr> 
      <th>{{$league{"competition.name"} }}</th> 
     </tr> 
     </thead> 
     <tbody> 
     @foreach($data_user as $match) 
      <tr> 
       <th>{{$match->starting_date }}</th> 
       <th>{{$match->starting_time }}</th> 
       <th>{{$match->status }}</th> 
       <th>{{$match{"homeTeam.name"} }}</th> 
       <th>{{$match->home_score }} : {{ $match->away_score }} </th> 
       <th>{{$match{"awayTeam.name"} }}</th> 
      </tr> 
     @endforeach 
     </tbody> 
    </table> 
@endforeach