Prime-Chat/app/Http/Controllers/NewsController.php
2025-01-16 22:22:38 +04:00

78 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\NewsRequest;
use App\Models\News;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
class NewsController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): View
{
Gate::authorize('viewAny', News::class);
$news = News::all();
return view('news.index', compact('news'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
Gate::authorize('create', News::class);
return view('news.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(NewsRequest $request): RedirectResponse
{
Gate::authorize('create', News::class);
News::query()->create($request->validated());
return redirect()->route('news.index');
}
/**
* Show the form for editing the specified resource.
*/
public function edit(News $news): View
{
Gate::authorize('update', $news);
return view('news.edit', compact('news'));
}
/**
* Update the specified resource in storage.
*/
public function update(NewsRequest $request, News $news): RedirectResponse
{
Gate::authorize('update', $news);
$news->update($request->validated());
return redirect()->route('news.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(News $news): RedirectResponse
{
Gate::authorize('delete', $news);
$news->delete();
return redirect()->route('news.index');
}
}