app/Http/Controllers/Blog/Admin/CategoryController.php
/**
     * Update the specified resource in storage.
     *
     * @param BlogCategoryUpdateRequest $request
     * @param int $id
     * @return Response
     */
Update the specified resource in storage.
@param BlogCategoryUpdateRequest $request
@param int $id
@return Response
Update the specified resource in storage . @param BlogCategoryUpdateRequest $request @param int $id @return Response
public function update(BlogCategoryUpdateRequest $request, $id)
    {
        $item = $this->blogCategoryRepository->getEdit($id);
        if(empty($item)){
            return back()
                ->withErrors(['msg' => "Category id=[{$id}] not found"])
                ->withInput();
        }
        $data = $request->all();
        $result = $item->update($data);
        if($result){
            return redirect()
                ->route('blog.admin.categories.edit', $item->id)
                ->with(['success' => 'saved']);
        }else{
            return back()
                ->withErrors(['msg' => 'Save error'])
                ->withInput();
        }
    }
public function update ( BlogCategoryUpdateRequest $ request , $ id ) { $ item = $ this -> blogCategoryRepository -> getEdit ( $ id ) ; if ( empty ( $ item ) ) { return back ( ) -> withErrors ( [ 'msg' => " Category id=[ { $ id } ] not found " ] ) -> withInput ( ) ; } $ data = $ request -> all ( ) ; $ result = $ item -> update ( $ data ) ; if ( $ result ) { return redirect ( ) -> route ( 'blog.admin.categories.edit' , $ item -> id ) -> with ( [ 'success' => 'saved' ] ) ; } else { return back ( ) -> withErrors ( [ 'msg' => 'Save error' ] ) -> withInput ( ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .
/*
         * Создание ограничений для сохранения
         * */ //        $rules = [ //            'title'     =>  'required|min:5|max:200', //            'slug'      =>  'max:200', //            'description'   => 'string|max:500|min:3', //            'parent_id'     =>  'required|integer|exists:blog_categories,id', //exists from table //        ]; //$validationData = $this->validate($request, $rules); был выбор между двумя, но второй варик понравился больше :D //$validationData = $request->validate()->rules(); //$item = BlogCategory::find($id); //В обсервере //        if (($data['slug']) == null){ //            $data['slug'] = Str::slug($data['title']); //        } //        $result = $item->fill($data); //        $result->save();