samedi 27 février 2016

Grouping related models using Laravel 5.1 blade and HTML

Could a someone help me out of this, I am finding it hard grouping related models together using html table. The system I'm trying to come up with is a bidding system. Multiple users can bid on a product, and as well, multiple products. When the owner views his products, they should be grouped based on the product name. Let say a user posts 2 products, and 4 other users have bid on these products, the users' bid should be grouped under the product name, but I'm what I'm getting is that it groups each under different tables. This is my blade view:

<DIV style="color:#0000FF">
                    @foreach($myBuyers as $myQuotedProducts)
                            @foreach($product as $products)
                                @if($products->id === $myQuotedProducts->product_id)
                                    @if(count($products->productname) > 1)
                                <div style="color:#0000FF">
                                    <p>{!! $products->productname !!}</p>
                                    <TABLE>
                                    <TH>SELECT</TH><TH>PRODUCT</TH><TH>COMMENT</TH><TH>PRICE</TH>
                                        <TR><TD>{!! Form::radio('selectedButton' .$myQuotedProducts->product_id, $myQuotedProducts->product_id) !!}</TD><TD>{!! $products->productname !!}</TD><TD>{!! $myQuotedProducts->comments !!}</TD><TD>{!! $myQuotedProducts->price !!}</TD></TR>
                                    </TABLE>
                                </div>
                                @else
                                    <div style="color:#0000FF">
                                    <p>{!! $products->productname !!}</p>
                                    <TABLE>
                                    <TH>SELECT</TH><TH>PRODUCT</TH><TH>COMMENT</TH><TH>PRICE</TH>
                                        <TR><TD>{!! Form::radio('selectedButton' .$myQuotedProducts->product_id, $myQuotedProducts->product_id) !!}</TD><TD>{!! $products->productname !!}</TD><TD>{!! $myQuotedProducts->comments !!}</TD><TD>{!! $myQuotedProducts->price !!}</TD></TR>
                                    </TABLE>
                                </div>
                                @endif
                                @endif
                            @endforeach
                        @endforeach

                </DIV>

This is my controller:

public function index()
    {
        $product = Product::all();
        $myBuyers = BiddingComments::where('user_id', '=', Auth::user()->id)->orderBy('price', 'DESC')->get();

        return view('buyers.index')
        ->with('product', $product)
        ->with('myBuyers', $myBuyers);
    }

Please kindly see the attached screenshots to be well acquainted on what I want to achieve and what I'm getting.

This is what I want to achieve: This is what I want to achieve

This is what I'm getting now which is wrong enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire