Laravel, how to ignore an accessor

前端 未结 3 1661
面向向阳花
面向向阳花 2020-12-17 10:06

I have a model with a custom accessor so I get that custom attribute,

    class Order extends GSModel{

        $appends = [\'orderContents\'];

        publ         


        
3条回答
  •  执念已碎
    2020-12-17 10:43

    There's no way to do it in one go, so here's what you need:

    $openOrders = Order::open()->has('contents')->get(['id','date','tableName']);
    
    $openOrders->each(function ($order) {
      $order->setAppends([]);
    });
    

    Alternatively, you may use Laravel's Higher Order Messaging on the last step:

    $openOrders->each->setAppends([]);
    

提交回复
热议问题