app/Http/Controllers/Admin/CategoryController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $category=Category::findOrFail($id);
        $this->validate($request,[
            'title'=>'string|required',
            'summary'=>'string|nullable',
            'photo'=>'string|nullable',
            'status'=>'required|in:active,inactive',
            'is_parent'=>'sometimes|in:1',
            'parent_id'=>'nullable|exists:categories,id',
        ]);
        $data= $request->all();
        $data['is_parent']=$request->input('is_parent',0);
        $status=$category->fill($data)->save();
        if($status){
            request()->session()->flash('success','Category successfully updated');
        }
        else{
            request()->session()->flash('error','Error occurred, Please try again!');
        }
        return redirect()->route('category.index');
    }
public function update ( Request $ request , $ id ) { $ category = Category :: findOrFail ( $ id ) ; $ this -> validate ( $ request , [ 'title' => 'string|required' , 'summary' => 'string|nullable' , 'photo' => 'string|nullable' , 'status' => 'required|in:active,inactive' , 'is_parent' => 'sometimes|in:1' , 'parent_id' => 'nullable|exists:categories,id' , ] ) ; $ data = $ request -> all ( ) ; $ data [ 'is_parent' ] = $ request -> input ( 'is_parent' , 0 ) ; $ status = $ category -> fill ( $ data ) -> save ( ) ; if ( $ status ) { request ( ) -> session ( ) -> flash ( 'success' , 'Category successfully updated' ) ; } else { request ( ) -> session ( ) -> flash ( 'error' , 'Error occurred, Please try again!' ) ; } return redirect ( ) -> route ( 'category.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// return $data;