Laravel 取消序列化数据库中某列的错误

Laravel 取消序列化数据库中某列的错误,laravel,Laravel,因为有一天,当我想访问一个未序列化的列时,我的视图有一个例外。这真的很奇怪,因为在一些页面中它工作正常,而在另一些页面中我得到了一个错误 希望有人能帮助我。。我不知道为什么有时有效,有时无效。我还测试了base64_encode()和base64_decode(),但现在我的不同记录中的所有视图都出现错误 反序列化错误offet 这里是我创建新订单时的控制器 $order = new Order(); $order->cart = serialize($cart);

因为有一天,当我想访问一个未序列化的列时,我的视图有一个例外。这真的很奇怪,因为在一些页面中它工作正常,而在另一些页面中我得到了一个错误

希望有人能帮助我。。我不知道为什么有时有效,有时无效。我还测试了base64_encode()和base64_decode(),但现在我的不同记录中的所有视图都出现错误

反序列化错误offet

这里是我创建新订单时的控制器

     $order = new Order();
     $order->cart = serialize($cart);
     ...
     $order->save();
现在,当我取消序列化时,我的控制器

public function show($id)
  {
      $order = Order::findOrFail($id);
      $order->cart = unserialize($order->cart);
      $order->cart->totalPrice;
      $prix_total = $order->cart->totalPrice;
      $structure_id = $order->structure_id;
      $structure = Structure::where('id' , '=' , $structure_id)->first();
      $federation = Structure::where('id' , '1')->first();

      return view('cotisation_structure/show' , compact('prix_total', 'order' , 'structure' , 'federation'));

  }
现在,我的视图显示“购物车”列中的记录:

@foreach($order->cart->items as $item)
                       <tr>
                           @if(Auth::user()->isFederation())
                               <td><input type="checkbox" name="checkbox[]" value="{{$item['item']->id}}"></td>
                           @endif
                           <td><a href="{!! route('licencie.show', $item['item']->id) !!}">{{$item['item']->num_licence}}</a></td>
                           <th>{{$item['item']->lb_nom}}</th>
                           <th>{{$item['item']->lb_prenom}}</th>
                           <th>{{$item['item']->structure->nom_structure}}</th>
                               <td>
                                   @if($item['item']->lb_tricolore != null)
                                       {{$item['item']->lb_activite_tricolore}} - {{$item['item']->lb_tricolore}}
                                   @else
                                       {{$item['item']->activite_licencie->lb_activite}}
                                   @endif
                               </td>
                           <th>{{$item['item']->saison->lb_saison}}</th>
                           <th>{{$order->payment_method}}</th>
                           <th>{{$item['price']}} € </th>
                           <td>{{Carbon\Carbon::parse($order->date_achat)->format('d/m/Y')}}</td>
                       </tr>
                    @endforeach
@foreach($order->cart->items as$item)
@如果(Auth::user()->isFederation())
@恩迪夫
{{$item['item']->lb_nom}
{{$item['item']->lb_prenom}
{{$item['item']->structure->nom_structure}
@如果($item['item']->lb_tricolore!=null)
{{$item['item']->lb_activite_tricolore}-{{{$item['item']->lb_tricolore}
@否则
{{$item['item']->activite_licensie->lb_activite}
@恩迪夫
{{$item['item']->saison->lb_saison}
{{$order->payment_method}
{{$item['price']}}€
{{Carbon\Carbon::parse($order->date\u achat)->格式('d/m/Y')}
@endforeach

您可能将序列化字段存储在数据库表字段的
字符串类型中,并在255个字符处剥离


为了进一步调试,我建议将序列化数据保存到日志中,并在还原时保存。在这种情况下,您可以比较保存的数据是否与取出的数据相同。

谢谢您的回复!我使用“文本”作为列。这类字段的长度有限制?我应该使用longtext吗?取决于序列化数据的大小。案文65535(216)−1) 字节=64千字节媒体文本16777215(224−1) 字节=16 MiB长文本4294967295(232−1) 字节数=4。为确保安全,GiBi已更改为LONGTEXT。现在我再也没有例外了。这似乎有效。非常感谢您的帮助,先生!!!!