public function update($id) { $inputs['title'] = Jamesy\Sanitiser::trimInput(Input::get('title')); $inputs['content'] = Jamesy\Sanitiser::trimInput(Input::get('content')); $validation = Jamesy\MyValidations::validate($inputs, $this->rules); if ($validation != NULL) { return Redirect::back()->withErrors($validation)->withInput(); } else { $anchors = []; $anchor_string = ''; if (Input::has('anchors')) { $anchors = array_unique(explode(",", Str::lower(Input::get('anchors')))); $anchors = array_filter($anchors, function ($i) { return $i != 'type in your anchors separated by a space or comma'; }); foreach ($anchors as $key => $value) { $anchor_string .= $value; $anchor_string .= $key == count($anchors) - 1 ? '' : ','; } } $page = Page::find($id); $slug = $page->slug; if (Str::slug($inputs['title']) != $slug) { $existingSlugs = Page::lists('slug'); $slug = Jamesy\MyValidations::makeSlug($existingSlugs, Str::slug($inputs['title'])); } $page->user_id = $this->user->id; $page->title = $inputs['title']; $page->slug = $slug; $page->content = $inputs['content']; $page->anchors = Str::length($anchor_string) ? $anchor_string : NULL; $page->save(); return Redirect::to('dashboard/pages')->withSuccess('Page updated'); } }