1
|
|
|
<?php |
2
|
|
|
namespace Xetaravel\Http\Controllers\Blog; |
3
|
|
|
|
4
|
|
|
use Xetaravel\Http\Controllers\Controller; |
5
|
|
|
use Xetaravel\Models\Article; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
|
8
|
|
|
class ArticleController extends Controller |
9
|
|
|
{ |
10
|
|
|
public function __construct() |
11
|
|
|
{ |
12
|
|
|
parent::__construct(); |
13
|
|
|
|
14
|
|
|
$this->breadcrumbs->addCrumb('Blog', route('blog_article_index')); |
|
|
|
|
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Show the list of all articles. |
19
|
|
|
* |
20
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
21
|
|
|
*/ |
22
|
|
|
public function index() |
23
|
|
|
{ |
24
|
|
|
$articles = Article::with('category', 'user') |
|
|
|
|
25
|
|
|
->paginate(config('xetaravel.pagination.blog.article_per_page')); |
26
|
|
|
|
27
|
|
|
return view('Blog::article.index', ['articles' => $articles, 'breadcrumbs' => $this->breadcrumbs]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Show the article by his id. |
32
|
|
|
* |
33
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function show(Request $request, $slug, $id) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$article = Article::with('category', 'user', 'comments') |
|
|
|
|
38
|
|
|
->where('id', $id) |
39
|
|
|
->first(); |
40
|
|
|
|
41
|
|
|
if (is_null($article)) { |
42
|
|
|
return redirect() |
43
|
|
|
->route('blog_article_index') |
44
|
|
|
->with('danger', 'This article doesn\'t exist or has been deleted !'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$comments = $article->comments()->paginate(config('xetaravel.pagination.blog.comment_per_page')); |
48
|
|
|
|
49
|
|
|
$this->breadcrumbs->addCrumb( |
50
|
|
|
"Article : " . e($article->title), |
51
|
|
|
route( |
52
|
|
|
'blog_article_show', |
53
|
|
|
['slug' => $article->category->slug, 'id' => $article->category->id] |
54
|
|
|
) |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
return view( |
58
|
|
|
'Blog::article.show', |
59
|
|
|
['article' => $article, 'comments' => $comments, 'breadcrumbs' => $this->breadcrumbs] |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: