1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ergare17\Articles\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\User; |
6
|
|
|
use Ergare17\Articles\Http\Requests\DestroyArticle; |
7
|
|
|
use Ergare17\Articles\Http\Requests\ShowArticle; |
8
|
|
|
use Ergare17\Articles\Http\Requests\StoreArticle; |
9
|
|
|
use Ergare17\Articles\Http\Requests\UpdateArticle; |
10
|
|
|
use Ergare17\Articles\Models\Article; |
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
use Illuminate\Support\Facades\App; |
13
|
|
|
use Redirect; |
14
|
|
|
use Session; |
15
|
|
|
|
16
|
|
|
class ArticleController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Display a listing of the resource. |
20
|
|
|
* |
21
|
|
|
* @return \Illuminate\Http\Response |
22
|
|
|
*/ |
23
|
|
|
public function index() |
24
|
|
|
{ |
25
|
|
|
// CRUD -> Retrieve --> List |
26
|
|
|
// BREAD -> Browse Read Edit Add Delete |
27
|
|
|
$articles = Article::all(); |
28
|
|
|
return view('articles::list_article', ['articles' => $articles]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Show the form for creating a new resource. |
33
|
|
|
* |
34
|
|
|
* @return \Illuminate\Http\Response |
35
|
|
|
*/ |
36
|
|
|
public function create() |
37
|
|
|
{ |
38
|
|
|
$users = User::all(); |
39
|
|
|
|
40
|
|
|
return view('articles::create_article', ['users' => $users]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Store a newly created resource in storage. |
45
|
|
|
* |
46
|
|
|
* @param \Illuminate\Http\Request $request |
47
|
|
|
* @return \Illuminate\Http\Response |
48
|
|
|
*/ |
49
|
|
|
public function store(StoreArticle $request) |
50
|
|
|
{ |
51
|
|
|
Article::create([ |
|
|
|
|
52
|
|
|
'title' => $request->title, |
53
|
|
|
'description' => $request->description, |
54
|
|
|
'user_id' => $request->user_id, |
55
|
|
|
'read' => false, |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
Session::flash('status', 'Created ok!'); |
59
|
|
|
return Redirect::to('/articles_php/create'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Display the specified resource. |
64
|
|
|
* |
65
|
|
|
* @param \App\Article $article |
66
|
|
|
* @return \Illuminate\Http\Response |
67
|
|
|
*/ |
68
|
|
|
public function show(ShowArticle $request, Article $article) |
69
|
|
|
{ |
70
|
|
|
// return view('show_article',compact('article')); |
|
|
|
|
71
|
|
|
return view('articles::show_article', compact('article')); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Display the specified resource. |
76
|
|
|
* |
77
|
|
|
* @param \App\Article $article |
|
|
|
|
78
|
|
|
* @return \Illuminate\Http\Response |
79
|
|
|
*/ |
80
|
|
|
public function show1($id) |
81
|
|
|
{ |
82
|
|
|
dump($id); |
83
|
|
|
dump($article = Article::find($id)); |
84
|
|
|
|
85
|
|
|
// if ($article == null)abort(404); |
|
|
|
|
86
|
|
|
// try{ |
87
|
|
|
// $article = Article::findOrFail($id); |
88
|
|
|
// } catch(\Exception $e){ |
89
|
|
|
// abort(404); |
90
|
|
|
// } |
91
|
|
|
$article = Article::findOrFail($id); |
92
|
|
|
|
93
|
|
|
dump($article->title); |
94
|
|
|
// return $article; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Show the form for editing the specified resource. |
99
|
|
|
* |
100
|
|
|
* @param \App\Article $article |
101
|
|
|
* @return \Illuminate\Http\Response |
102
|
|
|
*/ |
103
|
|
|
public function edit(Article $article) |
104
|
|
|
{ |
105
|
|
|
$users = User::all(); |
106
|
|
|
|
107
|
|
|
return view('articles::edit_article', ['article' => $article,'users' => $users]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Update the specified resource in storage. |
112
|
|
|
* |
113
|
|
|
* @param \Illuminate\Http\Request $request |
114
|
|
|
* @param \App\Article $article |
115
|
|
|
* @return \Illuminate\Http\Response |
116
|
|
|
*/ |
117
|
|
|
public function update(UpdateArticle $request, Article $article) |
118
|
|
|
{ |
119
|
|
|
$article->update($request->only(['title','description','user_id'])); |
120
|
|
|
|
121
|
|
|
Session::flash('status', 'Edited ok!'); |
122
|
|
|
return Redirect::to('/articles_php/edit/'.$article->id); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Remove the specified resource from storage. |
127
|
|
|
* |
128
|
|
|
* @param \App\Article $article |
129
|
|
|
* @return \Illuminate\Http\Response |
130
|
|
|
*/ |
131
|
|
|
public function destroy(DestroyArticle $request, Article $article) |
132
|
|
|
{ |
133
|
|
|
$article->delete(); |
134
|
|
|
Session::flash('status', 'Article was deleted successful!'); |
135
|
|
|
return Redirect::to('/articles_php'); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.