Laravel, how to ignore an accessor

前端 未结 3 1679
面向向阳花
面向向阳花 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:53

    Okay I'm not saying this is a good solution, but it works and you get around using a loop...

    Add this to your model:

    public static $withoutAppends = false;
    
    protected function getArrayableAppends()
    {
        if(self::$withoutAppends){
            return [];
        }
        return parent::getArrayableAppends();
    }
    

    Then when you want to disable the $appends properties:

    Order::$withoutAppends = true;
    $openOrders = Order::open()->has('contents')->get(['id','date','tableName']);
    

提交回复
热议问题