我想要过滤一个json字段(post)在数据库中与自序建设者。
我需要帮助来询问顺序。
attributes: array:17 [▼
    "id" => 2
    "admin_id" => 0
    "email" => "test@gmail.com"
    "fullname" => "asdasdasd"
    "subject" => "asdasdasdasd"
    "desc" => """
      sadasd\r\n
      """
    "cell_phone" => "091200000000"
    **"post" => "{"modir": 0, "saken": 0, "ozv_modir": 0}"**
    "elevator_spec" => null
    "type" => null
    "control" => null
    "count_stop" => null
    "door_type" => null
    "lift_capacity" => null
    "insurance" => null
    "created_at" => "2017-10-28 21:24:54"
    "updated_at" => "2017-10-28 21:24:54"
  ]发布于 2017-10-29 09:29:04
You should use setter and getter in the model in case of that specific field that you want .
     public function setPostAttribute($value)
    {
        $this->attributes['post'] = json_encode($value, JSON_UNESCAPED_UNICODE);
    }
   public function getPostAttribute()
    {
        $model = new $this;
        $jsonToConvert = $this->attributes['post'];
        $modelArray = $model->fromJson($jsonToConvert);
        return $model->newInstance($modelArray);
    }
after that in your controller :
    Orders::where('post->modir', 0)->get(https://stackoverflow.com/questions/46998615
复制相似问题