mardi 27 novembre 2018

I am trying to retrieve data from database under if condition

So I am trying to get the YEAR from my database and check if it is 2018..if it is then the view should display all books that have been released in 2018. Here is my code:

-> My controller:

  public function getYear(){
    $year = Book::all();
    return view('/pages/trending',compact('year'));
}

->my view

@foreach ($year as $y)
@if($y=='2018')
<td></td>

@endif
@endforeach

All I am getting is that the variable year is not defined.

Aucun commentaire:

Enregistrer un commentaire