doujia9833 2018-10-06 12:47
浏览 244

Laravel显示:“unserialize():当表列为空时,错误在6字节的偏移0处”

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分