Could you help me with this case? I saw that this is done but I get the error that I attached so I do not know what I'm doing wrong /:
public function index()
{
// Inicializa @rownum
DB::statement(DB::raw('SET @rownum = 0'));
// Realiza la consulta
$tops = DB::table('articles')
->select(DB::raw('id','head','description', '@rownum := @rownum + 1 as rownum'))
->where('approve', '=', 'Aprobado')
->where('important','Destacado')
->orderBy('id', 'DESC')
->paginate(5);
return view('index',compact('tops'));
}
Now I have the problem when executing the query, this says to me:
Undefined property: stdClass :: $ head (View: C: \ xampp \ htdocs \ IndieSonico \ resources \ views \ index.blade.php)
This way I am calling you in my view:
@foreach($tops as $top)
<div id="tops0" class="card" style="border:none !important; margin: 0;">
<a href="{{ route('show',$top->id.$top->head) }}">
<img class="card-img-top" src="../images/{{$top->path}}" alt="Card image cap" style="height: 112px">
</a>
<a href="{{ route('show',$top->id.$top->head) }}" class="a-corregido2">
<span id="">{{$top->rownum}}</span><span class="title-tops">{{ $top ->head }}</span>
</a>
</div>
@endforeach