<?php

namespace App\Http\Controllers\Web;

use App\Model\MediaCategoryModel;
use App\Tool\SrsHookValidate;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MediaCategoryController extends Controller
{
    public function index(Request $request){

        $result = handler_drive(function () use ($request) {


            $catgList = MediaCategoryModel::catgListPage($request);
            return $catgList;
        });
        $data['name'] = $request->name;
        $data['media_categories'] = $result;


        return view('admin.media_category.list',$data);
    }


    /**
     * 会员添加
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @throws ControllerException
     */
    public function create()
    {
        return view('admin.media_category.add');
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ControllerException
     */
    public function store(Request $request){

        handler_drive(function () use($request){

            SrsHookValidate::srsHookCallback($request,[
                'name'              => 'required',
                'media_category_id' => '',
                'status'            => '',
                'description'       => ''
            ]);

            MediaCategoryModel::addMediaCatg($request);

        });
        return success();
    }

}
