53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Helpers\Paginator;
|
|
use App\Http\Requestes\CropYieldRequest;
|
|
use App\Http\Requestes\CropYieldUpdateRequest;
|
|
use App\Http\Resources\CropYieldResource;
|
|
use App\Models\CropYield;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CropYieldController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$query = CropYield::filter($request->all());
|
|
$totalNum = $query->sum('yield'); //总产量
|
|
$list = $query->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50));
|
|
$list->load(['base', 'createdBy']);
|
|
|
|
return $this->json([
|
|
'total' => $totalNum,
|
|
'list' => CropYieldResource::collection($list),
|
|
]);
|
|
}
|
|
|
|
public function store(CropYieldRequest $request)
|
|
{
|
|
//-todo
|
|
return $this->success('添加成功');
|
|
}
|
|
|
|
public function show(CropYield $cropYield)
|
|
{
|
|
$cropYield->load(['base', 'crop', 'createdBy']);
|
|
|
|
return $this->json(CropYieldResource::make($cropYield));
|
|
}
|
|
|
|
public function update(CropYield $cropYield, CropYieldUpdateRequest $request)
|
|
{
|
|
//-todo
|
|
return $this->success('修改成功');
|
|
}
|
|
|
|
public function destroy(CropYield $cropYield)
|
|
{
|
|
$cropYield->delete();
|
|
|
|
return $this->success('删除成功');
|
|
}
|
|
}
|