* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace App\Repositories\Transformers; use App\Repositories\Models\Model; use League\Fractal\TransformerAbstract; interface BaseShuntInterface { public function mobileDetailTransform($model); public function mobileTransform($model); public function pcTransform($model); public function detailTransform($model); } class BaseShuntTransformer extends TransformerAbstract implements BaseShuntInterface { public function transform(Model $model) { if (is_mobile()) { if ($this->isId()) { return $this->mobileDetailTransform($model); } return $this->mobileTransform($model); } if ($this->isId()) { return $this->detailTransform($model); } return $this->pcTransform($model); } /** * 是否为详情 * @return bool */ private function isId() { return request()->has('id'); } public function mobileDetailTransform($model) { return []; } public function mobileTransform($model) { return []; } public function detailTransform($model) { return []; } public function pcTransform($model) { return []; } }