blog-app/views/post/index.blade.php
2021-11-13 14:19:55 +08:00

60 lines
2.2 KiB
PHP

@extends('layout.master')
@section('content')
<div class="posts">
@if(count($posts) == 0)
<h3 class="text-secondary">No content</h3>
@endif
@foreach($posts as $post)
<div>
<span class="text-secondary">{{ explode(' ', $post->create_at)[0] }}</span>
@if(isset($_SESSION['is_auth']) && $post->author == $_SESSION['username'])
<a href="/post/{{ $post->id }}/edit" class="text-primary">Edit</a>
<a href="#" class="text-danger" data-toggle="modal" data-target="#confirm-modal" data-action="/post/{{ $post->id }}/delete">Delete</a>
@endif
</div>
<h2 class="title">
<a href="/post/{{ $post->id }}">{!! isset($keyword) ? preg_replace('/' . preg_quote(e($keyword)) . '/i', '<span class="match">$0</span>', e($post->title)) : e($post->title) !!}</a>
</h2>
@endforeach
<ul class="pager">
@if($page > 1)
<li class="previous"><a href="{{ $pager_uri }}/{{ $page - 1 }}">&larr; Prev</a></li>
@endif
@if(! $is_last)
<li class="next"><a href="{{ $pager_uri }}/{{ $page + 1 }}">Next &rarr;</a></li>
@endif
</ul>
<div class="modal fade" id="confirm-modal" tabindex="-1" role="dialog" aria-labelledby="confirm-label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirm-label">Confirmation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete this post?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<form method="POST" action="" id="delete-form">
<input type="hidden" name="_token" value="{{ $_SESSION['_token'] }}">
<button type="submit" class="btn btn-danger">Yes</button>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('sidebar')
@include('layout.sidebar')
@endsection