mirror of
https://github.com/henry4682/finance_app.git
synced 2026-07-16 00:10:00 +00:00
37 lines
838 B
PHP
37 lines
838 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\CategoryRule;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
|
|
class CategoryRuleController extends Controller
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'keyword' => 'required|string|max:255',
|
|
'category_id' => 'required|exists:categories,id',
|
|
]);
|
|
|
|
CategoryRule::create([
|
|
...$validated,
|
|
'user_id' => auth()->id(),
|
|
]);
|
|
|
|
return redirect()->back();
|
|
}
|
|
|
|
public function destroy(CategoryRule $categoryRule)
|
|
{
|
|
if ($categoryRule->user_id !== auth()->id()) {
|
|
abort(403);
|
|
}
|
|
|
|
$categoryRule->delete();
|
|
return redirect()->back();
|
|
}
|
|
} |