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:
48
app/Http/Controllers/CategoryController.php
Normal file
48
app/Http/Controllers/CategoryController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'color' => 'nullable|string|max:7',
|
||||
'icon' => 'nullable|string|max:50',
|
||||
]);
|
||||
|
||||
Category::create([
|
||||
...$validated,
|
||||
'user_id' => auth()->id(),
|
||||
]);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function update(Request $request, Category $category)
|
||||
{
|
||||
$this->authorize('update', $category);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'color' => 'nullable|string|max:7',
|
||||
]);
|
||||
|
||||
$category->update($validated);
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
$this->authorize('delete', $category);
|
||||
$category->delete();
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user