mirror of
https://github.com/henry4682/finance_app.git
synced 2026-07-16 00:10:00 +00:00
buid new app
This commit is contained in:
37
app/Http/Controllers/CategoryRuleController.php
Normal file
37
app/Http/Controllers/CategoryRuleController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user