<?php

use Livewire\Component;
use App\Models\Post;

return new class extends Component
{
    public function render()
    {
        if (!auth()->user()->can('view posts')) {
            abort(403);
        }
        return $this->view()->layout('layouts::auth');
    }

    public function delete($id)
    {
        if (!auth()->user()->can('delete posts')) {
            session()->flash('error', 'Unauthorized.');
            return;
        }
        Post::find($id)->delete();
        session()->flash('message', 'Post deleted successfully.');
    }

    public function with()
    {
        return [
            'posts' => Post::with('category')->latest()->get(),
        ];
    }

    protected function view($data = [])
    {
        return app('view')->file('D:\02-my freelance\00-DR_Padhi\DR_PADHI\storage\framework/views/livewire/views/0088713b.blade.php', $data);
    }
};
