From 4f107431db2f7073c033ce14d8caa76cb7109a19 Mon Sep 17 00:00:00 2001 From: vagrant Date: Wed, 4 Apr 2018 10:19:02 +0000 Subject: [PATCH] Topic index page --- app/Http/Controllers/TopicsController.php | 70 +++---- app/Models/Topic.php | 12 +- composer.json | 1 + composer.lock | 131 +++++++++++- config/debugbar.php | 201 +++++++++++++++++++ public/css/app.css | 33 +++ resources/assets/sass/app.scss | 31 +++ resources/views/topics/_sidebar.blade.php | 1 + resources/views/topics/_topic_list.blade.php | 52 +++++ resources/views/topics/index.blade.php | 69 ++----- storage/debugbar/.gitignore | 2 + 11 files changed, 517 insertions(+), 86 deletions(-) create mode 100644 config/debugbar.php create mode 100644 resources/views/topics/_sidebar.blade.php create mode 100644 resources/views/topics/_topic_list.blade.php create mode 100644 storage/debugbar/.gitignore diff --git a/app/Http/Controllers/TopicsController.php b/app/Http/Controllers/TopicsController.php index f97eaaf..28bd6d3 100644 --- a/app/Http/Controllers/TopicsController.php +++ b/app/Http/Controllers/TopicsController.php @@ -9,52 +9,52 @@ class TopicsController extends Controller { - public function __construct() + public function __construct () { - $this->middleware('auth', ['except' => ['index', 'show']]); + $this->middleware ( 'auth' , [ 'except' => [ 'index' , 'show' ] ] ); } - public function index() - { - $topics = Topic::paginate(); - return view('topics.index', compact('topics')); - } + public function index () + { + $topics = Topic::with ( 'user' , 'category' )->paginate ( 30 ); + return view ( 'topics.index' , compact ( 'topics' ) ); + } - public function show(Topic $topic) + public function show ( Topic $topic ) { - return view('topics.show', compact('topic')); + return view ( 'topics.show' , compact ( 'topic' ) ); } - public function create(Topic $topic) - { - return view('topics.create_and_edit', compact('topic')); - } + public function create ( Topic $topic ) + { + return view ( 'topics.create_and_edit' , compact ( 'topic' ) ); + } - public function store(TopicRequest $request) - { - $topic = Topic::create($request->all()); - return redirect()->route('topics.show', $topic->id)->with('message', 'Created successfully.'); - } + public function store ( TopicRequest $request ) + { + $topic = Topic::create ( $request->all () ); + return redirect ()->route ( 'topics.show' , $topic->id )->with ( 'message' , 'Created successfully.' ); + } - public function edit(Topic $topic) - { - $this->authorize('update', $topic); - return view('topics.create_and_edit', compact('topic')); - } + public function edit ( Topic $topic ) + { + $this->authorize ( 'update' , $topic ); + return view ( 'topics.create_and_edit' , compact ( 'topic' ) ); + } - public function update(TopicRequest $request, Topic $topic) - { - $this->authorize('update', $topic); - $topic->update($request->all()); + public function update ( TopicRequest $request , Topic $topic ) + { + $this->authorize ( 'update' , $topic ); + $topic->update ( $request->all () ); - return redirect()->route('topics.show', $topic->id)->with('message', 'Updated successfully.'); - } + return redirect ()->route ( 'topics.show' , $topic->id )->with ( 'message' , 'Updated successfully.' ); + } - public function destroy(Topic $topic) - { - $this->authorize('destroy', $topic); - $topic->delete(); + public function destroy ( Topic $topic ) + { + $this->authorize ( 'destroy' , $topic ); + $topic->delete (); - return redirect()->route('topics.index')->with('message', 'Deleted successfully.'); - } + return redirect ()->route ( 'topics.index' )->with ( 'message' , 'Deleted successfully.' ); + } } \ No newline at end of file diff --git a/app/Models/Topic.php b/app/Models/Topic.php index 1a8890b..070166a 100644 --- a/app/Models/Topic.php +++ b/app/Models/Topic.php @@ -4,5 +4,15 @@ class Topic extends Model { - protected $fillable = ['title', 'body', 'user_id', 'category_id', 'reply_count', 'view_count', 'last_reply_user_id', 'order', 'excerpt', 'slug']; + protected $fillable = [ 'title' , 'body' , 'user_id' , 'category_id' , 'reply_count' , 'view_count' , 'last_reply_user_id' , 'order' , 'excerpt' , 'slug' ]; + + public function category () + { + return $this->belongsTo ( Category::class ); + } + + public function user () + { + return $this->belongsTo ( User::class ); + } } diff --git a/composer.json b/composer.json index d2131f5..6e32ea5 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "overtrue/laravel-lang": "~3.0" }, "require-dev": { + "barryvdh/laravel-debugbar": "~3.1", "filp/whoops": "~2.0", "fzaninotto/faker": "~1.4", "mockery/mockery": "~1.0", diff --git a/composer.lock b/composer.lock index b5511b2..e4d7037 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "623c79b95af3bb6af9d1a55e78df296c", + "content-hash": "6ab2a5dd922446f475930e91774f6915", "packages": [ { "name": "caouecs/laravel-lang", @@ -2571,6 +2571,74 @@ } ], "packages-dev": [ + { + "name": "barryvdh/laravel-debugbar", + "version": "v3.1.4", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-debugbar.git", + "reference": "7a91480cc6e597caed5117a3c5d685f06d35c5a1" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/barryvdh/laravel-debugbar/7a91480cc6e597caed5117a3c5d685f06d35c5a1.zip", + "reference": "7a91480cc6e597caed5117a3c5d685f06d35c5a1", + "shasum": "" + }, + "require": { + "illuminate/routing": "5.5.x|5.6.x", + "illuminate/session": "5.5.x|5.6.x", + "illuminate/support": "5.5.x|5.6.x", + "maximebf/debugbar": "~1.15.0", + "php": ">=7.0", + "symfony/debug": "^3|^4", + "symfony/finder": "^3|^4" + }, + "require-dev": { + "illuminate/framework": "5.5.x" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Debugbar\\ServiceProvider" + ], + "aliases": { + "Debugbar": "Barryvdh\\Debugbar\\Facade" + } + } + }, + "autoload": { + "psr-4": { + "Barryvdh\\Debugbar\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "PHP Debugbar integration for Laravel", + "keywords": [ + "debug", + "debugbar", + "laravel", + "profiler", + "webprofiler" + ], + "time": "2018-03-06T08:35:31+00:00" + }, { "name": "doctrine/instantiator", "version": "1.1.0", @@ -2784,6 +2852,67 @@ ], "time": "2016-01-20T08:20:44+00:00" }, + { + "name": "maximebf/debugbar", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/maximebf/php-debugbar.git", + "reference": "30e7d60937ee5f1320975ca9bc7bcdd44d500f07" + }, + "dist": { + "type": "zip", + "url": "https://files.phpcomposer.com/files/maximebf/php-debugbar/30e7d60937ee5f1320975ca9bc7bcdd44d500f07.zip", + "reference": "30e7d60937ee5f1320975ca9bc7bcdd44d500f07", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "psr/log": "^1.0", + "symfony/var-dumper": "^2.6|^3.0|^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0|^5.0" + }, + "suggest": { + "kriswallsmith/assetic": "The best way to manage assets", + "monolog/monolog": "Log using Monolog", + "predis/predis": "Redis storage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "autoload": { + "psr-4": { + "DebugBar\\": "src/DebugBar/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Bouroumeau-Fuseau", + "email": "maxime.bouroumeau@gmail.com", + "homepage": "http://maximebf.com" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Debug bar in the browser for php application", + "homepage": "https://github.com/maximebf/php-debugbar", + "keywords": [ + "debug", + "debugbar" + ], + "time": "2017-12-15T11:13:46+00:00" + }, { "name": "mockery/mockery", "version": "1.0", diff --git a/config/debugbar.php b/config/debugbar.php new file mode 100644 index 0000000..24c79fb --- /dev/null +++ b/config/debugbar.php @@ -0,0 +1,201 @@ + env('DEBUGBAR_ENABLED', true), + 'except' => [ + // + ], + + /* + |-------------------------------------------------------------------------- + | Storage settings + |-------------------------------------------------------------------------- + | + | DebugBar stores data for session/ajax requests. + | You can disable this, so the debugbar stores data in headers/session, + | but this can cause problems with large data collectors. + | By default, file storage (in the storage folder) is used. Redis and PDO + | can also be used. For PDO, run the package migrations first. + | + */ + 'storage' => [ + 'enabled' => true, + 'driver' => 'file', // redis, file, pdo, custom + 'path' => storage_path('debugbar'), // For file driver + 'connection' => null, // Leave null for default connection (Redis/PDO) + 'provider' => '' // Instance of StorageInterface for custom driver + ], + + /* + |-------------------------------------------------------------------------- + | Vendors + |-------------------------------------------------------------------------- + | + | Vendor files are included by default, but can be set to false. + | This can also be set to 'js' or 'css', to only include javascript or css vendor files. + | Vendor files are for css: font-awesome (including fonts) and highlight.js (css files) + | and for js: jquery and and highlight.js + | So if you want syntax highlighting, set it to true. + | jQuery is set to not conflict with existing jQuery scripts. + | + */ + + 'include_vendors' => true, + + /* + |-------------------------------------------------------------------------- + | Capture Ajax Requests + |-------------------------------------------------------------------------- + | + | The Debugbar can capture Ajax requests and display them. If you don't want this (ie. because of errors), + | you can use this option to disable sending the data through the headers. + | + | Optionally, you can also send ServerTiming headers on ajax requests for the Chrome DevTools. + */ + + 'capture_ajax' => true, + 'add_ajax_timing' => false, + + /* + |-------------------------------------------------------------------------- + | Custom Error Handler for Deprecated warnings + |-------------------------------------------------------------------------- + | + | When enabled, the Debugbar shows deprecated warnings for Symfony components + | in the Messages tab. + | + */ + 'error_handler' => false, + + /* + |-------------------------------------------------------------------------- + | Clockwork integration + |-------------------------------------------------------------------------- + | + | The Debugbar can emulate the Clockwork headers, so you can use the Chrome + | Extension, without the server-side code. It uses Debugbar collectors instead. + | + */ + 'clockwork' => false, + + /* + |-------------------------------------------------------------------------- + | DataCollectors + |-------------------------------------------------------------------------- + | + | Enable/disable DataCollectors + | + */ + + 'collectors' => [ + 'phpinfo' => true, // Php version + 'messages' => true, // Messages + 'time' => true, // Time Datalogger + 'memory' => true, // Memory usage + 'exceptions' => true, // Exception displayer + 'log' => true, // Logs from Monolog (merged in messages if enabled) + 'db' => true, // Show database (PDO) queries and bindings + 'views' => true, // Views with their data + 'route' => true, // Current route information + 'auth' => true, // Display Laravel authentication status + 'gate' => true, // Display Laravel Gate checks + 'session' => true, // Display session data + 'symfony_request' => true, // Only one can be enabled.. + 'mail' => true, // Catch mail messages + 'laravel' => false, // Laravel version and environment + 'events' => false, // All events fired + 'default_request' => false, // Regular or special Symfony request logger + 'logs' => false, // Add the latest log messages + 'files' => false, // Show the included files + 'config' => false, // Display config settings + 'cache' => false, // Display cache events + ], + + /* + |-------------------------------------------------------------------------- + | Extra options + |-------------------------------------------------------------------------- + | + | Configure some DataCollectors + | + */ + + 'options' => [ + 'auth' => [ + 'show_name' => true, // Also show the users name/email in the debugbar + ], + 'db' => [ + 'with_params' => true, // Render SQL with the parameters substituted + 'backtrace' => true, // Use a backtrace to find the origin of the query in your files. + 'timeline' => false, // Add the queries to the timeline + 'explain' => [ // Show EXPLAIN output on queries + 'enabled' => false, + 'types' => ['SELECT'], // ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+ + ], + 'hints' => true, // Show hints for common mistakes + ], + 'mail' => [ + 'full_log' => false + ], + 'views' => [ + 'data' => false, //Note: Can slow down the application, because the data can be quite large.. + ], + 'route' => [ + 'label' => true // show complete route on bar + ], + 'logs' => [ + 'file' => null + ], + 'cache' => [ + 'values' => true // collect cache values + ], + ], + + /* + |-------------------------------------------------------------------------- + | Inject Debugbar in Response + |-------------------------------------------------------------------------- + | + | Usually, the debugbar is added just before , by listening to the + | Response after the App is done. If you disable this, you have to add them + | in your template yourself. See http://phpdebugbar.com/docs/rendering.html + | + */ + + 'inject' => true, + + /* + |-------------------------------------------------------------------------- + | DebugBar route prefix + |-------------------------------------------------------------------------- + | + | Sometimes you want to set route prefix to be used by DebugBar to load + | its resources from. Usually the need comes from misconfigured web server or + | from trying to overcome bugs like this: http://trac.nginx.org/nginx/ticket/97 + | + */ + 'route_prefix' => '_debugbar', + + /* + |-------------------------------------------------------------------------- + | DebugBar route domain + |-------------------------------------------------------------------------- + | + | By default DebugBar route served from the same domain that request served. + | To override default domain, specify it as a non-empty value. + */ + 'route_domain' => null, +]; diff --git a/public/css/app.css b/public/css/app.css index f2648d6..0783cb6 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -8417,3 +8417,36 @@ body { margin-bottom: 0px; } +/* Topic Index Page */ + +.topics-index-page .topic-list .nav > li > a { + position: relative; + display: block; + padding: 5px 14px; + font-size: 0.9em; +} + +.topics-index-page .topic-list a { + color: #444444; +} + +.topics-index-page .topic-list .meta { + font-size: 0.9em; + color: #b3b3b3; +} + +.topics-index-page .topic-list .meta a { + color: #b3b3b3; +} + +.topics-index-page .topic-list .badge { + background-color: #d8d8d8; +} + +.topics-index-page .topic-list hr { + margin-top: 12px; + margin-bottom: 12px; + border: 0; + border-top: 1px solid #dcebf5; +} + diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index 4224a18..3ef3ddb 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -70,4 +70,35 @@ body { margin-bottom: 0px; } } +} + +/* Topic Index Page */ +.topics-index-page { + .topic-list { + .nav > li > a { + position: relative; + display: block; + padding: 5px 14px; + font-size: 0.9em; + } + a { + color: #444444; + } + .meta { + font-size:0.9em; + color: #b3b3b3; + a { + color: #b3b3b3; + } + } + .badge { + background-color: #d8d8d8; + } + hr { + margin-top: 12px; + margin-bottom: 12px; + border: 0; + border-top: 1px solid #dcebf5; + } + } } \ No newline at end of file diff --git a/resources/views/topics/_sidebar.blade.php b/resources/views/topics/_sidebar.blade.php new file mode 100644 index 0000000..5643d18 --- /dev/null +++ b/resources/views/topics/_sidebar.blade.php @@ -0,0 +1 @@ +右边导航栏 diff --git a/resources/views/topics/_topic_list.blade.php b/resources/views/topics/_topic_list.blade.php new file mode 100644 index 0000000..afd628e --- /dev/null +++ b/resources/views/topics/_topic_list.blade.php @@ -0,0 +1,52 @@ +@if (count($topics)) + + + +@else +
暂无数据 ~_~
+@endif \ No newline at end of file diff --git a/resources/views/topics/index.blade.php b/resources/views/topics/index.blade.php index b5fb787..c53e25f 100644 --- a/resources/views/topics/index.blade.php +++ b/resources/views/topics/index.blade.php @@ -1,61 +1,32 @@ @extends('layouts.app') -@section('content') -
-
-
-
-

- Topic - Create -

-
- -
- @if($topics->count()) - - - - - - - - +@section('title', '话题列表') - - @foreach($topics as $topic) - - +@section('content') - - - - - @endforeach - -
#Title Body User_id Category_id Reply_count View_count Last_reply_user_id Order Excerpt SlugOPTIONS
{{$topic->id}}{{$topic->title}} {{$topic->body}} {{$topic->user_id}} {{$topic->category_id}} {{$topic->reply_count}} {{$topic->view_count}} {{$topic->last_reply_user_id}} {{$topic->order}} {{$topic->excerpt}} {{$topic->slug}} - - - - - - - +
+
+
-
- {{csrf_field()}} - + - -
-
+
+ {{-- 话题列表 --}} + @include('topics._topic_list', ['topics' => $topics]) + {{-- 分页 --}} {!! $topics->render() !!} - @else -

Empty!

- @endif +
+ +
-
@endsection \ No newline at end of file diff --git a/storage/debugbar/.gitignore b/storage/debugbar/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/debugbar/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore