on
Laravel 5.3 Blog System - Admin Dashboard - All Posts
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') All Posts Add New Post {!! Form::open(['method'=>'GET','url'=>'admin/posts/','class'=>'navbar-form navbar-left','role'=>'search']) !!} {!! Form::close() !!} # Title Description Post Url's Image Created Actions @foreach($posts as $post) {{$no++}} {{$post->title}} {{$post->description}} {{ str_limit($post->body, $limit = 120, $end = '.......') }} {!! (''.$post->slug.'') !!} {{$post->created_at}} @endforeach {!! $posts->links() !!} @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, // ... ],
from http://rudalson.tistory.com/195 by ccl(A) rewrite - 2021-10-27 18:59:58