public function post_update($locale, $id) { $advertisement = Advertisement::where('published', 1)->where('id', $id)->first(); if (!$advertisement || Auth::user()->id != $advertisement->user_id) { abort(404); } $input = Input::all(); $validator = Validator::make($input, $this->rules); if ($validator->fails()) { return redirect()->back()->with('error', $validator->errors()->all())->withInput(); } $advertisement->title = $input['title']; $advertisement->category_id = $input['category']; $advertisement->description = $input['description']; $advertisement->user_id = Auth::user()->id; $slug = Slug::make($advertisement->id . '-' . $advertisement->title); $advertisement->url = $slug; $advertisement->save(); $category = Category::select('url')->where('id', $advertisement->category_id)->first()->url; return redirect()->route('advertisement', ['locale' => $locale, 'category' => $category, 'url' => $slug])->with('success', trans('message.advertisement_update')); }
public function category_edit_post($id) { $cat = Category::find($id); if (!$cat) { abort(404); } $input = Input::all(); $rules = ['uk_title' => 'required|unique:categories,uk_title,' . $cat->id, 'ru_title' => 'required', 'icon' => 'required']; $validator = Validator::make($input, $rules); if ($validator->fails()) { return redirect()->back()->with('error', $validator->errors()->all())->withInput(); } $cat->uk_title = $input['uk_title']; $cat->ru_title = $input['ru_title']; $cat->icon = $input['icon']; $cat->url = Slug::make($cat->uk_title); $cat->save(); return redirect()->route('admin_categories')->with('success', 'Категорія успішно змінена!'); }