This repository was archived by the owner on Feb 23, 2021. It is now read-only.
File tree 4 files changed +53
-2
lines changed
4 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,9 @@ SMTP_HOST=smtp.mailgun.org
23
23
SMTP_PORT = 587
24
24
SMTP_USERNAME = (null)
25
25
SMTP_PASSWORD = (null)
26
+
27
+ # ## Pixabay API設定
28
+ # ## 請至網站註冊取得,否則沒有貓貓圖
29
+ # ## http://pixabay.com/api/docs/
30
+ PIXABAY_USERNAME = (null)
31
+ PIXABAY_KEY = (null)
Original file line number Diff line number Diff line change
1
+ <?php namespace App ;
2
+
3
+ use GuzzleHttp \Client ;
4
+ use Illuminate \Database \Eloquent \Model ;
5
+
6
+ class Cat extends Model
7
+ {
8
+
9
+ /*
10
+ * 隨機貓貓圖
11
+ */
12
+ public static function random ()
13
+ {
14
+ $ username = env ('PIXABAY_USERNAME ' );
15
+ $ key = env ('PIXABAY_KEY ' );
16
+ //檢查username與key
17
+ if (empty ($ username ) || empty ($ key )) {
18
+ return null ;
19
+ }
20
+ //抓取最新幾張圖,從中隨機(5-200)
21
+ $ number = 50 ;
22
+ //API請求
23
+ $ client = new Client ();
24
+ $ options = array (
25
+ 'username ' => $ username ,
26
+ 'key ' => $ key ,
27
+ 'image_type ' => 'photo ' ,
28
+ 'min_width ' => '600 ' ,
29
+ 'q ' => 'cute+cat ' ,
30
+ 'per_page ' => $ number ,
31
+ 'order ' => 'latest '
32
+ );
33
+ $ response = $ client ->get ('http://pixabay.com/api ' , ['query ' => $ options ]);
34
+ $ json = $ response ->json ();
35
+ return $ json ["hits " ][rand (0 , $ number - 1 )]["webformatURL " ];
36
+ }
37
+
38
+ }
Original file line number Diff line number Diff line change 1
1
<?php namespace App \Exceptions ;
2
2
3
+ use App \Cat ;
3
4
use Exception ;
4
5
use Illuminate \Foundation \Exceptions \Handler as ExceptionHandler ;
5
6
use Symfony \Component \Debug \ExceptionHandler as SymfonyDisplayer ;
@@ -115,9 +116,11 @@ protected function renderHttpException(HttpException $e)
115
116
);
116
117
117
118
if (array_key_exists ($ status , $ http_codes )) {
119
+ $ pic = Cat::random ();
118
120
$ error = array (
119
121
'code ' => $ status ,
120
- 'message ' => $ http_codes [$ status ]
122
+ 'message ' => $ http_codes [$ status ],
123
+ 'pic ' => $ pic
121
124
);
122
125
return response ()->view ("errors.error " , $ error , $ status );
123
126
} else {
Original file line number Diff line number Diff line change 7
7
@section (' content' )
8
8
<div class =" container" >
9
9
<div class =" row text-center" >
10
- {!! HTML:: image (' pic/' . $code . ' .jpg' ,' Bad Request' ); ! !}
10
+ <h1 >{{ $code } } </h1 >
11
+ <h1 >{{ $message } } </h1 >
12
+ @if (! empty ($pic ) )
13
+ {!! HTML:: image ($pic , $message , [' width' => ' 600px' ]); ! !}
14
+ @endif
11
15
</div >
12
16
</div >
13
17
@endsection
You can’t perform that action at this time.
0 commit comments