-1

i want to show the categorie list without showing duplicated ones

my controller code :

public function showActualite(){

    $actualites=DB::table('actualites')->distinct('categorie')->orderBy('created_at', 'DESC')->paginate(6);
    return view ('AllActualite',['actualites' => $actualites]);
}

My view :

@foreach ($actualites as $act)

      <span style="text-transform: capitalize;" > <a href="/actualites/{{$act->categorie}}"> {{$act->categorie}} </a></span>

     <span style="text-transform: capitalize;">  </span>
    @endforeach
    </div>
    <div class="row">

        @foreach($actualites as $act)
      <div class="col-lg-6">
        <div class="box wow fadeInLeft">
          <div class="icon"><i class="fa fa-newspaper-o"></i></div>
          <h4 class="title"><a href="/actualites/consulter/{{$act->id}}">{{$act->categorie}}</a></h4>
          <p class="description">{{$act->titre}}</p>


        </div>
      </div>

      @endforeach
Imed Jadli
  • 19
  • 2

2 Answers2

1

I believe your code should work, but in general i would not use DB logic. A more Laravel version of this would be. Latest is a syntax sugar for the same order by logic. See of this solves the problem.

$actualites = Actualites::query()->distinct('categorie')->latest()->paginate(6);
mrhn
  • 17,961
  • 4
  • 27
  • 46
0

All your answer can be found in this post

$actualites= Actuality::distinct()->get(['categorie']);

Eloquent is used.

TeachMe
  • 535
  • 1
  • 5
  • 16