<?php

namespace App\Http\Controllers\Api;

use App\Models\Concentration;
use App\Models\Email;
use App\Models\News;
use Exception;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

class ConcentrationController extends BaseController
{

    // 创建
    public function create(Request $request) {
        $data = Concentration::create([
            'content' => $request->input('content')
        ]);

        return $this->response($data);
    }

    public function getOne(Request $request) {
        $data = Concentration::findOrFail($request->input('id'));
        return $this->response($data);
    }

    // 列表
    public function list(Request $request) {
        $per_page = $request->input('per_page') ?: 10;
        $data = Concentration::query()->orderBy('id','desc')->paginate($per_page);
        return $this->response($data);
    }

    // 更新
    public function update(Request $request) {
        $model = Concentration::findOrFail($request->input('id'));

        if(!empty($request->input('content'))) $model->content =$request->input('content');

        $model->save();

        return $this->response($model);
    }

    // 禁用启用
    public function showHide(Request $request) {
        $model = Concentration::findOrFail($request->input('id'));

        $model->status = !$model->status;
        $model->save();

        return $this->response($model);
    }

    // 删除
    public function delete(Request $request) {
        $model = Concentration::findOrFail($request->input('id'));
        $model->delete();
        return $this->response($model);
    }
}

