0% found this document useful (0 votes)
6 views7 pages

Crud - Laravel - Extraold Code

The document outlines a table displaying posts created by the authenticated user, including details such as title, description, cover image, and status. It includes functionality for editing and deleting posts, as well as a message indicating when no posts have been created yet. The table is structured to show user-specific posts with options for managing them effectively.

Uploaded by

shifaamir04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Crud - Laravel - Extraold Code

The document outlines a table displaying posts created by the authenticated user, including details such as title, description, cover image, and status. It includes functionality for editing and deleting posts, as well as a message indicating when no posts have been created yet. The table is structured to show user-specific posts with options for managing them effectively.

Uploaded by

shifaamir04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

<tbody class="table-border-bottom-0">

@if ($posts->isNotEmpty())

<!-- counter to display numbers in ASC


order -->
@php $counter = ($posts->currentPage() - 1)
* $posts->perPage() + 1 @endphp

<!-- foreach loop to display posts -->


@foreach ($posts as $post)
@if ($post->created_by == auth()->id())
<tr>
<td value="{{ $post-
>id }}">{{ $counter }}</td>
<td>{{ $post->title }}</td>
<td>{{ $post->description
}}</td>

<td style="justify-items:
center;">
<ul
class="list-unstyled m-
0 avatar-group d-flex align-items-center">
<li data-bs-
toggle="tooltip" data-popup="tooltip-custom"
data-bs-
placement="top" class="avatar avatar-xs pull-up"
title="{{ $post-
>title }}">
<img
src="{{ asset($post->cover_image) }}" alt="Cover_Img"
class="rounded-
circle" />
</li>
</ul>
</td>

<td style="justify-items:
center;">
@if ($post->postFiles-
>isNotEmpty())
<ul
class="list-
unstyled m-0 avatar-group d-flex align-items-center">
@foreach ($post-
>postFiles as $file)
<li data-bs-
toggle="tooltip" data-popup="tooltip-custom"
data-bs-
placement="top"

class="avatar avatar-xs pull-up"

title="{{ $post->title }}">


<img
src="{{ asset($file->image_name) }}"

alt="Cover_Img" class="rounded-circle" />


</li>
@endforeach
</ul>
@else
<ul
class="list-
unstyled m-0 avatar-group d-flex align-items-center">
<li data-bs-
toggle="tooltip" data-popup="tooltip-custom"
data-bs-
placement="top" class="avatar avatar-xs pull-up"

title="{{ $post->title }}">


<span>
No
additional images available.
</span>
</li>
</ul>
@endif
</td>

{{-- @can('Update User Status')


--}}
<td>
@if ($post->status ==
'draft')
<a href="post/{{ $post-
>id }}"
class="btn btn-xs
me-1 mb-1 btn-secondary rounded">
Draft
</a>
@elseif ($post->status ==
'publish')
<a href="post/{{ $post-
>id }}"
class="btn btn-xs
me-1 mb-1 btn-success rounded">
Publish
</a>
@endif
</td>
{{-- @endcan --}}

<td>
<div class="dropdown">
<button type="button"
class="btn p-0
dropdown-toggle hide-arrow"
data-bs-
toggle="dropdown">
<i class="bx bx-
dots-vertical-rounded"></i>
</button>
<div class="dropdown-
menu">
{{-- @can('Update
User') --}}
<a class="dropdown-
item"

href="{{ route('posts.edit', $post->id) }}">


<i class="bx
bx-edit-alt me-1"></i>
Edit</a>
{{-- @endcan --}}

{{-- @can('Delete
User') --}}
<button
class="dropdown-item"

onclick="deletePost({{ $post->id }})"

href="javascript:void(0);">
<i class="bx
bx-trash me-1"></i>
Delete</button>
{{-- @endcan --}}
</div>
</div>
</td>
</tr>

@php $counter++; @endphp


@else
<div class="col-sm-6 col-lg-12 my-4
justify-item-center">
<div class="card bg-primary
text-white text-center p-4">
<figure class="mb-0">
<blockquote
class="blockquote">
<p>There's Nothing
Here Yet!
You haven’t
created any posts yet.
</p>
</blockquote>
<figcaption
class="blockquote-footer mb-0 text-white">
CREATE POST <cite
title="Source Title">Source Title</cite>
</figcaption>
</figure>
</div>
</div>
@endif
@endforeach

@endif

</tbody>
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

whole table div

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

<div class="table-responsive text-nowrap text-center">


<table class="table">
<thead>
<tr class="text-nowrap table-active">
<th>#</th>
<th>Title</th>
<th>Description</th>
<th>Cover Image</th>
<th>Files</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>

<tbody class="table-border-bottom-0">

<!-- Filter posts created by the authenticated


user -->
@php
$userPosts = $posts->filter(function
($post) {
return $post->created_by == auth()-
>id();
});
@endphp

@if ($userPosts->isNotEmpty())
<!-- Counter to display numbers in ASC
order -->
@php $counter = ($posts->currentPage() - 1)
* $posts->perPage() + 1 @endphp
<!-- Foreach loop to display user posts -->
@foreach ($userPosts as $post)
<tr>
<td value="{{ $post-
>id }}">{{ $counter }}</td>
<td>{{ $post->title }}</td>
<td>{{ $post->description }}</td>
<td style="justify-items: center;">
<ul class="list-unstyled m-0
avatar-group d-flex align-items-center">
<li data-bs-
toggle="tooltip" data-popup="tooltip-custom"
data-bs-placement="top"
class="avatar avatar-xs pull-up"
title="{{ $post-
>title }}">
<img
src="{{ asset($post->cover_image) }}" alt="Cover_Img"
class="rounded-
circle" />
</li>
</ul>
</td>
<td style="justify-items: center;">
@if ($post->postFiles-
>isNotEmpty())
<ul
class="list-unstyled m-
0 avatar-group d-flex align-items-center">
@foreach ($post-
>postFiles as $file)
<li data-bs-
toggle="tooltip" data-popup="tooltip-custom"
data-bs-
placement="top" class="avatar avatar-xs pull-up"

title="{{ $post->title }}">


<img
src="{{ asset($file->image_name) }}"
alt="File
Image" class="rounded-circle" />
</li>
@endforeach
</ul>
@else
<ul
class="list-unstyled m-
0 avatar-group d-flex align-items-center">
<li data-bs-
toggle="tooltip" data-popup="tooltip-custom"
data-bs-
placement="top" class="avatar avatar-xs pull-up"
title="{{ $post-
>title }}">
<span>No additional
images available.</span>
</li>
</ul>
@endif
</td>
<td>
@if ($post->status == 'draft')
<a href="post/{{ $post-
>id }}"
class="btn btn-xs me-1
mb-1 btn-secondary rounded">Draft</a>
@elseif ($post->status ==
'publish')
<a href="post/{{ $post-
>id }}"
class="btn btn-xs me-1
mb-1 btn-success rounded">Publish</a>
@endif
</td>
<td>
<div class="dropdown">
<button type="button"
class="btn p-0 dropdown-toggle hide-arrow"
data-bs-
toggle="dropdown">
<i class="bx bx-dots-
vertical-rounded"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-
item"

href="{{ route('posts.edit', $post->id) }}">


<i class="bx bx-
edit-alt me-1"></i>Edit</a>
<button
class="dropdown-item"

onclick="deletePost({{ $post->id }})"

href="javascript:void(0);">
<i class="bx bx-
trash me-1"></i>Delete</button>
</div>
</div>
</td>
</tr>

@php $counter++; @endphp


@endforeach
@else
<div class="col-xs-12 col-sm-12 col-md-12
col-lg-12 my-4 ">
<div class="card bg-primary text-white
text-center p-4">
<figure class="mb-0">
<blockquote class="blockquote">
<p>There's Nothing Here
Yet! You haven’t created any posts.</p>
</blockquote>
<figcaption class="blockquote-
footer mb-0 text-white">
Start by clicking the <cite
title="Source Title">Create Post</cite> button to share your thoughts, ideas, or
updates!
</figcaption>
</figure>
</div>
</div>

@endif

</tbody>

</table>
</div>

You might also like