laravel-12/resources/views/components/post-card.blade.php

34 lines
1.2 KiB
PHP

@props([
'post',
'showActions' => true,
])
<div class="list-group-item">
<h5 class="mb-1">
<a href="{{ route('posts.show', $post) }}" class="text-decoration-none">
{{ $post->title }}
</a>
@if($post->user_id !== auth()->id())
<span class="badge bg-secondary">автор: {{ $post->user->name }}</span>
@endif
</h5>
<p class="mb-1">{{ Str::limit($post->content, 100) }}</p>
<small class="text-muted">{{ $post->created_at->diffForHumans() }}</small>
@if($showActions)
<div class="float-end">
@can('update-post', $post)
<a href="{{ route('posts.edit', $post) }}" class="btn btn-sm btn-primary">Edit</a>
@endcan
@can('delete-post', $post)
<form action="{{ route('posts.destroy', $post) }}" method="POST" class="d-inline">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-danger"
onclick="return confirm('Are you sure you want to delete this post?')">Delete</button>
</form>
@endcan
</div>
@endif
</div>