Skip to content

Commit

Permalink
fix #8
Browse files Browse the repository at this point in the history
  • Loading branch information
cong5 committed May 12, 2017
1 parent 9dad3fd commit 95239c8
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 437 deletions.
20 changes: 13 additions & 7 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Persimmon\Services\ServerChanSend;

class Handler extends ExceptionHandler
{
Expand All @@ -27,32 +28,37 @@ class Handler extends ExceptionHandler
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
app(\Persimmon\Services\ServerChanSend::class)->send($exception);
//app(\Persimmon\Services\ServerChanSend::class)->send($exception);

parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
if (!config('app.debug')) {
return response()->view('errors.error', ['message'=>'很抱歉,页面找不到了, 换一个页面试试吧。'], 404);
} else {
return parent::render($request, $exception);
}
}

/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
Expand Down
14 changes: 8 additions & 6 deletions app/Http/Controllers/App/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\App;


use Illuminate\Support\Facades\Session;
use Models\Links;
use Persimmon\Interfaces\CreatorInterface;
use App\Http\Controllers\Controller;
Expand Down Expand Up @@ -37,6 +38,8 @@ public function posts($flag)
{
$post = app(\Persimmon\Services\RedisCache::class)->cachePost($flag);

!empty($post) ?: abort(404, '很抱歉,页面找不到了。');

Posts::increment('views', 1);

return view('app.post')->with(compact('post'));
Expand All @@ -51,6 +54,8 @@ public function tags($tag)

$tags = Tags::where('tags_name', $tag)->first();

!empty($tags) ?: abort(404, '很抱歉,页面找不到了。');

$posts = $tags->posts()->paginate(15);

return view('app.home')->with(compact('posts', 'tags'));
Expand All @@ -66,6 +71,8 @@ public function category($flag)
{
$category = Categorys::where('category_flag', $flag)->first();

!empty($category) ?: abort(404, '很抱歉,页面找不到了。');

$posts = $category->posts()->paginate(15);

return view('app.home')->with(compact('posts', 'category'));
Expand All @@ -78,6 +85,7 @@ public function category($flag)
public function friends()
{
$links = Links::all();

return view('app.friends')->with(compact('links'));
}

Expand Down Expand Up @@ -121,10 +129,4 @@ public function creatorSuccess($model)
{
$this->response = ['status' => 'success', 'id' => $model->id, 'info' => '评论发布成功'];
}

public function debug()
{
//abc::findOrFail(100);
//die('bala,bala,bala~~~');
}
}
11 changes: 7 additions & 4 deletions app/Persimmon/Services/RedisCache.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Session;
use Models\Options;
use Models\Posts;

Expand Down Expand Up @@ -41,10 +42,12 @@ public function cachePost($flag)
$post = cache($key);
if (empty($post)) {
$post = Posts::OfType('post')->where('flag', $flag)->first();
$post->categories;
$post->tags;
$post->user;
cache([$key => $post], $this->expiresAt);
if(!empty($post)){
$post->categories;
$post->tags;
$post->user;
cache([$key => $post], $this->expiresAt);
}
}
return $post;
}
Expand Down
2 changes: 1 addition & 1 deletion public/backend/css/app.css

Large diffs are not rendered by default.

Loading

0 comments on commit 95239c8

Please sign in to comment.