<?php 

namespace App\Services\Views;

use App\Models\Block;

class BlockService
{
    use \App\Traits\ContentTrait;
    
    //调取说明页内容
    public function block($slug = '', $item = '', $key = '')
    {
        static $data = null;

        $data[$slug] = $data[$slug] ?? Block::with('description')->where('slug', $slug)->first();

        if ($item) {
            if ($item == 'imgs' && is_numeric($key)) {
                return $data[$slug]->description->{$item}[$key] ?? '';
            }

            return $data[$slug]->description->{$item} ?? '';
        }

        return $data[$slug] ?? '';
    }
}