<?php

namespace App\Http\Controllers;


use App\Models\Category;
use App\Models\Staff;

class StaffController extends Controller
{
    public $category_id = 16;


    public function index()
    {
        $category = Category::find($this->category_id);

        $parent  = $category;
        $topCate = $category->getTopCategory();

        if ($category->childrens->isEmpty() && $category->parent) {
            $parent = $category->parent;
        }

        $staffs = Staff::shown()->latest('order')->get();

        $data = [
            'staffs'   => $staffs,
            'category' => $category,
            'parent'   => $parent,
            'topCate'  => $topCate,
        ];

        return view('staff.index', $data);
    }

    /**
     * Notes: description
     *
     * @Author: 玄尘
     * @Date  : 2021/10/8 14:54
     * @param  \App\Models\Staff  $staff
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function show(Staff $staff)
    {
        $parent = $category = $staff->category;
        if ($category->children->isEmpty() && $category->parent) {
            $parent = $category->parent;
        }

        $topCate = $category->getTopCategory();

        return view('staff.show', compact('staff', 'category', 'topCate', 'parent'));

    }

}
