初始化
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\GlossaryTerm;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GlossaryController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$terms = GlossaryTerm::orderBy('term')->paginate(20);
|
||||
|
||||
return view('admin.glossary.index', compact('terms'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
return view('admin.glossary.form', ['term' => null]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'term' => ['required', 'string', 'max:80'],
|
||||
'slug' => ['required', 'string', 'max:90', 'unique:glossary_terms,slug'],
|
||||
'definition' => ['required', 'string'],
|
||||
'aliases' => ['nullable', 'string', 'max:255'],
|
||||
'category' => ['nullable', 'string', 'max:60'],
|
||||
]);
|
||||
|
||||
GlossaryTerm::create($data);
|
||||
|
||||
return redirect()->route('admin.glossary.index')->with('success', '术语已创建');
|
||||
}
|
||||
|
||||
public function edit(GlossaryTerm $glossaryTerm): View
|
||||
{
|
||||
return view('admin.glossary.form', ['term' => $glossaryTerm]);
|
||||
}
|
||||
|
||||
public function update(Request $request, GlossaryTerm $glossaryTerm)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'term' => ['required', 'string', 'max:80'],
|
||||
'slug' => ['required', 'string', 'max:90', 'unique:glossary_terms,slug,' . $glossaryTerm->id],
|
||||
'definition' => ['required', 'string'],
|
||||
'aliases' => ['nullable', 'string', 'max:255'],
|
||||
'category' => ['nullable', 'string', 'max:60'],
|
||||
]);
|
||||
|
||||
$glossaryTerm->update($data);
|
||||
|
||||
return redirect()->route('admin.glossary.index')->with('success', '术语已更新');
|
||||
}
|
||||
|
||||
public function destroy(GlossaryTerm $glossaryTerm)
|
||||
{
|
||||
$glossaryTerm->delete();
|
||||
|
||||
return redirect()->route('admin.glossary.index')->with('success', '术语已删除');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user