I have a table(books) with column named(genre) with serialize array.
when I show the page using
public function show($id)
{
$books = Book::findOrFail($id);
return view('books.show')->with('books', $books);
}
if the table column has array it will display the data. if the column is empty it should display "empty" but whenever the column is empty it will throw error "unserialize(): Error at offset 0 of 6 bytes".
@if(!empty($books->genre))
<dt class="font-weight-bold">Genre:</dt>
<dd>-
@foreach (unserialize($books->genre) as $item)
<span class="pr-3">{{ $item }}</span>
@endforeach
</dd>
@else
<h1>Empty</h1>
@endif
I also have trie using isset() and is_array() instead of !empty() and still it failed.