Created
November 5, 2018 10:17
-
-
Save wpupru/34d44b8f6a0b28b021d9ff2cdc1b9fc1 to your computer and use it in GitHub Desktop.
PagesAdd Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use App\Page; | |
| use Illuminate\Http\Request; | |
| use Illuminate\Support\Facades\Validator; | |
| class PagesAddController extends Controller | |
| { | |
| public function execute(Request $request) | |
| { | |
| if($request->isMethod('post')) | |
| { | |
| // dd($request); | |
| $input = $request->except('_token'); | |
| $rules = [ | |
| 'name' => 'required|max:255', | |
| 'alias' => 'required|unique:pages|max:255', | |
| 'text' => 'required' | |
| ]; | |
| //dd($input); | |
| $validator = Validator::make($input, $rules); | |
| if ($validator->fails()) | |
| { | |
| return redirect()->route('pagesAdd')->withErrors($validator)->withInput(); | |
| } | |
| //dd($input); | |
| if($request->hasFile('images')) | |
| { | |
| $file = $request->file('images'); | |
| $input['images'] = $file->getClientOriginalName(); | |
| $file->move(public_path(). 'assets/img/', $input['images']); | |
| } | |
| // dd($input); | |
| $page = new Page(); | |
| // $page->unguard(); | |
| $page->fill($input); | |
| if($page->save()) | |
| { | |
| return redirect('admin')->with('status', 'Страница добавлена'); | |
| } | |
| } | |
| if(view()->exists('admin.pages_add')) | |
| { | |
| $data = [ | |
| 'title' => 'Добавить страницу' | |
| ]; | |
| return view('admin.pages_add', $data); | |
| } | |
| abort(404); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment