80 lines
2.8 KiB
PHP
80 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Solution;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class SolutionController extends Controller
|
|
{
|
|
public function index(): View
|
|
{
|
|
$solutions = Solution::orderBy('sort')->orderBy('name')->paginate(20);
|
|
|
|
return view('admin.solutions.index', compact('solutions'));
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
return view('admin.solutions.form', ['solution' => null]);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$data = $request->validate([
|
|
'name' => ['required', 'string', 'max:120'],
|
|
'slug' => ['required', 'string', 'max:120', 'unique:solutions,slug'],
|
|
'power_segment' => ['nullable', 'in:lt30,30-65,65-100,gt100'],
|
|
'application' => ['nullable', 'in:charger,powerbank,car,dock'],
|
|
'chip_platform' => ['nullable', 'in:protocol,soc,rectifier'],
|
|
'power' => ['nullable', 'string', 'max:40'],
|
|
'summary' => ['nullable', 'string', 'max:255'],
|
|
'advantages' => ['nullable', 'string'],
|
|
'description' => ['nullable', 'string'],
|
|
'cover' => ['nullable', 'string', 'max:255'],
|
|
'status' => ['required', 'in:published,draft'],
|
|
'sort' => ['integer'],
|
|
]);
|
|
|
|
Solution::create($data);
|
|
|
|
return redirect()->route('admin.solutions.index')->with('success', '方案已创建');
|
|
}
|
|
|
|
public function edit(Solution $solution): View
|
|
{
|
|
return view('admin.solutions.form', compact('solution'));
|
|
}
|
|
|
|
public function update(Request $request, Solution $solution)
|
|
{
|
|
$data = $request->validate([
|
|
'name' => ['required', 'string', 'max:120'],
|
|
'slug' => ['required', 'string', 'max:120', 'unique:solutions,slug,' . $solution->id],
|
|
'power_segment' => ['nullable', 'in:lt30,30-65,65-100,gt100'],
|
|
'application' => ['nullable', 'in:charger,powerbank,car,dock'],
|
|
'chip_platform' => ['nullable', 'in:protocol,soc,rectifier'],
|
|
'power' => ['nullable', 'string', 'max:40'],
|
|
'summary' => ['nullable', 'string', 'max:255'],
|
|
'advantages' => ['nullable', 'string'],
|
|
'description' => ['nullable', 'string'],
|
|
'cover' => ['nullable', 'string', 'max:255'],
|
|
'status' => ['required', 'in:published,draft'],
|
|
'sort' => ['integer'],
|
|
]);
|
|
|
|
$solution->update($data);
|
|
|
|
return redirect()->route('admin.solutions.index')->with('success', '方案已更新');
|
|
}
|
|
|
|
public function destroy(Solution $solution)
|
|
{
|
|
$solution->delete();
|
|
|
|
return redirect()->route('admin.solutions.index')->with('success', '方案已删除');
|
|
}
|
|
}
|