jeremykenedy /
laravel-material-design
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace App\Http\Controllers; |
||||||
| 4 | |||||||
| 5 | use App\Models\Theme; |
||||||
| 6 | use App\Models\User; |
||||||
| 7 | use Illuminate\Http\Request; |
||||||
| 8 | use Illuminate\Support\Facades\Input; |
||||||
| 9 | use Validator; |
||||||
| 10 | |||||||
| 11 | class ThemesManagementController extends Controller |
||||||
| 12 | { |
||||||
| 13 | /** |
||||||
| 14 | * Create a new controller instance. |
||||||
| 15 | * |
||||||
| 16 | * @return void |
||||||
| 17 | */ |
||||||
| 18 | public function __construct() |
||||||
| 19 | { |
||||||
| 20 | $this->middleware('auth'); |
||||||
| 21 | } |
||||||
| 22 | |||||||
| 23 | /** |
||||||
| 24 | * Display a listing of the resource. |
||||||
| 25 | * |
||||||
| 26 | * @return \Illuminate\Http\Response |
||||||
| 27 | */ |
||||||
| 28 | public function index() |
||||||
| 29 | { |
||||||
| 30 | $users = User::all(); |
||||||
| 31 | |||||||
| 32 | $themes = Theme::orderBy('name', 'asc')->get(); |
||||||
| 33 | |||||||
| 34 | return View('themesmanagement.show-themes', compact('themes', 'users')); |
||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 35 | } |
||||||
| 36 | |||||||
| 37 | /** |
||||||
| 38 | * Show the form for creating a new resource. |
||||||
| 39 | * |
||||||
| 40 | * @return \Illuminate\Http\Response |
||||||
| 41 | */ |
||||||
| 42 | public function create() |
||||||
| 43 | { |
||||||
| 44 | return view('themesmanagement.add-theme'); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 45 | } |
||||||
| 46 | |||||||
| 47 | /** |
||||||
| 48 | * Store a newly created resource in storage. |
||||||
| 49 | * |
||||||
| 50 | * @param \Illuminate\Http\Request $request |
||||||
| 51 | * |
||||||
| 52 | * @return \Illuminate\Http\Response |
||||||
| 53 | */ |
||||||
| 54 | public function store(Request $request) |
||||||
| 55 | { |
||||||
| 56 | $input = Input::only('name', 'link', 'notes', 'status'); |
||||||
| 57 | |||||||
| 58 | $validator = Validator::make($input, Theme::rules()); |
||||||
| 59 | |||||||
| 60 | if ($validator->fails()) { |
||||||
| 61 | $this->throwValidationException( |
||||||
|
0 ignored issues
–
show
The method
throwValidationException() does not exist on App\Http\Controllers\ThemesManagementController. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 62 | $request, |
||||||
| 63 | $validator |
||||||
| 64 | ); |
||||||
| 65 | |||||||
| 66 | return redirect('themes/create')->withErrors($validator)->withInput(); |
||||||
| 67 | } |
||||||
| 68 | |||||||
| 69 | $theme = Theme::create([ |
||||||
| 70 | 'name' => $request->input('name'), |
||||||
| 71 | 'link' => $request->input('link'), |
||||||
| 72 | 'notes' => $request->input('notes'), |
||||||
| 73 | 'status' => $request->input('status'), |
||||||
| 74 | 'taggable_id' => 0, |
||||||
| 75 | 'taggable_type' => 'theme', |
||||||
| 76 | ]); |
||||||
| 77 | |||||||
| 78 | $theme->taggable_id = $theme->id; |
||||||
| 79 | $theme->save(); |
||||||
| 80 | |||||||
| 81 | return redirect('themes/'.$theme->id)->with('success', trans('themes.createSuccess')); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 82 | } |
||||||
| 83 | |||||||
| 84 | /** |
||||||
| 85 | * Display the specified resource. |
||||||
| 86 | * |
||||||
| 87 | * @param int $id |
||||||
| 88 | * |
||||||
| 89 | * @return \Illuminate\Http\Response |
||||||
| 90 | */ |
||||||
| 91 | public function show($id) |
||||||
| 92 | { |
||||||
| 93 | $theme = Theme::find($id); |
||||||
| 94 | $users = User::all(); |
||||||
| 95 | $themeUsers = []; |
||||||
| 96 | |||||||
| 97 | foreach ($users as $user) { |
||||||
| 98 | if ($user->profile && $user->profile->theme_id === $theme->id) { |
||||||
| 99 | $themeUsers[] = $user; |
||||||
| 100 | } |
||||||
| 101 | } |
||||||
| 102 | |||||||
| 103 | $data = [ |
||||||
| 104 | 'mdlTheme' => $theme, |
||||||
| 105 | 'themeUsers' => $themeUsers, |
||||||
| 106 | ]; |
||||||
| 107 | |||||||
| 108 | return view('themesmanagement.show-theme')->with($data); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 109 | } |
||||||
| 110 | |||||||
| 111 | /** |
||||||
| 112 | * Show the form for editing the specified resource. |
||||||
| 113 | * |
||||||
| 114 | * @param int $id |
||||||
| 115 | * |
||||||
| 116 | * @return \Illuminate\Http\Response |
||||||
| 117 | */ |
||||||
| 118 | public function edit($id) |
||||||
| 119 | { |
||||||
| 120 | $theme = Theme::find($id); |
||||||
| 121 | $users = User::all(); |
||||||
| 122 | $themeUsers = []; |
||||||
| 123 | |||||||
| 124 | foreach ($users as $user) { |
||||||
| 125 | if ($user->profile && $user->profile->theme_id === $theme->id) { |
||||||
| 126 | $themeUsers[] = $user; |
||||||
| 127 | } |
||||||
| 128 | } |
||||||
| 129 | |||||||
| 130 | $data = [ |
||||||
| 131 | 'theme' => $theme, |
||||||
| 132 | 'themeUsers' => $themeUsers, |
||||||
| 133 | ]; |
||||||
| 134 | |||||||
| 135 | return view('themesmanagement.edit-theme')->with($data); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 136 | } |
||||||
| 137 | |||||||
| 138 | /** |
||||||
| 139 | * Update the specified resource in storage. |
||||||
| 140 | * |
||||||
| 141 | * @param \Illuminate\Http\Request $request |
||||||
| 142 | * @param int $id |
||||||
| 143 | * |
||||||
| 144 | * @return \Illuminate\Http\Response |
||||||
| 145 | */ |
||||||
| 146 | public function update(Request $request, $id) |
||||||
| 147 | { |
||||||
| 148 | $theme = Theme::find($id); |
||||||
| 149 | |||||||
| 150 | $input = Input::only('name', 'link', 'notes', 'status'); |
||||||
| 151 | |||||||
| 152 | $validator = Validator::make($input, Theme::rules($id)); |
||||||
| 153 | |||||||
| 154 | if ($validator->fails()) { |
||||||
| 155 | $this->throwValidationException( |
||||||
| 156 | $request, |
||||||
| 157 | $validator |
||||||
| 158 | ); |
||||||
| 159 | |||||||
| 160 | return redirect('themes/'.$theme->id.'/edit')->withErrors($validator)->withInput(); |
||||||
| 161 | } |
||||||
| 162 | |||||||
| 163 | $theme->fill($input)->save(); |
||||||
| 164 | |||||||
| 165 | return redirect('themes/'.$theme->id)->with('success', trans('themes.updateSuccess')); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 166 | } |
||||||
| 167 | |||||||
| 168 | /** |
||||||
| 169 | * Remove the specified resource from storage. |
||||||
| 170 | * |
||||||
| 171 | * @param int $id |
||||||
| 172 | * |
||||||
| 173 | * @return \Illuminate\Http\Response |
||||||
| 174 | */ |
||||||
| 175 | public function destroy($id) |
||||||
| 176 | { |
||||||
| 177 | $default = Theme::findOrFail(1); |
||||||
| 178 | $theme = Theme::findOrFail($id); |
||||||
| 179 | |||||||
| 180 | if ($theme->id != $default->id) { |
||||||
| 181 | $theme->delete(); |
||||||
| 182 | |||||||
| 183 | return redirect('themes')->with('success', trans('themes.deleteSuccess')); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 184 | } |
||||||
| 185 | |||||||
| 186 | return back()->with('error', trans('themes.deleteSelfError')); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 187 | } |
||||||
| 188 | |||||||
| 189 | public function template() |
||||||
| 190 | { |
||||||
| 191 | return View('themesmanagement.template'); |
||||||
| 192 | } |
||||||
| 193 | } |
||||||
| 194 |