vendredi 4 décembre 2015

How to display latest('updated_at') records in blade file of laravel

I am doing project in laravel. In my project there are two tables categories and subcategories. subcategories table has categoryid as foreign key.

subcategoryModel.php has following function

public function category(){
    return $this->belongsTo('App\Category');
}

In my blade file I am displaying my subcategories using category object as follows,

blade.php

    <div class="col-sm-6 col-align-left">
        @foreach($category as $c)
             <div class="form-group clearfix">
                   @if($c->subcategories->count() > 0)
                   <h4><b>Subcategories: </b></h4>
                   <div class="form-group clearfix">
                    @foreach($c->subcategories as $subcategory)
                        <h4>{{$subcategory->subcategoryname}}</h4>
                    @endforeach
                   </div>
                   @endif
      <h4><a href="{{ url('subcategories/'.$c->categoryid.'') }}" class =        "btn btn-primary">Add Subcategories</a></h4>
     </div>
    @endforeach
    </div>

This display correct data,but now I want to display data in the order they are updated/created. Is there any way to display data as per the requirement? I want to something into the blade file itself. How to do this? Please give suggestions.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire