반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- Tutorial
- Blade
- 당사자표시정정신청서
- cartalyst
- 보정명령
- Eclipse
- 인민공원
- Sentinel
- Python
- Laravel
- Bootstrap
- 개인사업자
- as후기
- Java
- elasticSearch
- 체당금
- 코로나
- javascript
- reactnative
- 소액임금체불
- auth
- php
- blockchain
- win32
- 코로나19
- 이더리움
- 사업자계좌
- 홈택스
- 전자소송
- vue
Archives
- Today
- Total
그냥 사는 이야기
Laravel 5.3 Blog System - Admin Dashboard - All Posts 본문
반응형
Admin PostController
Admin dashboard 에서 사용할 PostController를 별도로 만든다. 기존의 PostController와 이름이 같기 때문에 Auth 디렉토리 밑으로 생성한다.
php artisan make:controller Auth/PostController --resource
App/Http/Controllers/Auth/PostController
use App\Post;
use App\User;
class PostController extends Controller
{
public function index(Request $request)
{
$search = $request->get('search');
$posts = Post::where('title', 'like', '%'.$search.'%')
->where('active', 1)
->orderBy('created_at')
->paginate(3);
return view('admin/posts/allposts')->withPosts($posts);
}
}
routes/web.php
Route::group(['middleware' => ['auth']], function() {
...
Route::get('admin/posts/allposts', 'Auth\PostController@index'); // 추가
Route::resource('admin/posts', 'Auth\PostController'); // 추가
});
순서에 주의한다.
resources/views/admin/posts/allposts.blade.php
@extends('layouts.dashboard')
@section('content')
<h2 class="sub-header">All Posts</h2>
<div class="row">
<div class="col-md-9">
<a href="{{ url('admin/posts/new-post') }}" class="btn btn-primary btn-sm">Add New Post</a>
</div>
<div class="col-md-3">
{!! Form::open(['method'=>'GET','url'=>'admin/posts/','class'=>'navbar-form navbar-left','role'=>'search']) !!}
<div class="input-group custom-search-form">
<input type="text" name="search" class="form-control" placeholder="Search ....">
<span class="input-group-btn">
<button type="submit" class="btn btn-default-sm">
<i class="fa fa-search"></i>
</button>
</span>
</div>
{!! Form::close() !!}
</div>
</div>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Description</th>
<th>Post</th>
<th>Url's</th>
<th>Image</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $no=1; ?>
@foreach($posts as $post)
<tr>
<td>{{$no++}}</td>
<td>{{$post->title}}</td>
<td>{{$post->description}}</td>
<td>
{{ str_limit($post->body, $limit = 120, $end = '.......') }}
</td>
<td>
{!! ('<a href='.url("/".$post->slug).'>'.$post->slug.'</a>') !!}
</td>
<td>
<img src="{{ url('img/'.$post->images)}}" id ="showimages" style="max-width:100px;max-height:50px;float:left;">
</td>
<td>{{$post->created_at}}</td>
<td>
<form class="" action="" method="post">
<input type="hidden" name="_method" value="delete">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<a href="{{ url('admin/posts/editpost/'.$post->slug)}}" class="btn btn-primary btn-xs">
<span class="glyphicon glyphicon-edit"></span>
</a>
<a href="{{ url('admin/posts/deletepost/'.$post->id.'?_token='.csrf_token()) }}" onclick="return confirm('Are you sure to delete this data');" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash"></span>
</a>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<!-- pagination -->
{!! $posts->links() !!}
</div>
@endsection
HTML & Form 클래스 포함시키기
"require": {
...
"laravelcollective/html": "5.3.*"
},
composer update
config/app.php
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
...
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
'Development > Web' 카테고리의 다른 글
Laravel 5.3 Blog System - Admin Dashboard - Edit, Delete (0) | 2020.01.23 |
---|---|
Laravel 5.3 Blog System - Admin Dashboard - Create, Store (0) | 2020.01.23 |
Laravel 5.3 Blog System - Admin Dashboard (0) | 2020.01.23 |
Laravel 5.3 Blog System - Bootstrap theme view (0) | 2020.01.22 |
Laravel 5.3 Blog System - Post And Comments (2) | 2020.01.22 |
Comments