anilkumarthakur60
1 week ago
120
4
Laravel

i want to update specific column data

Posted 1 week ago by anilkumarthakur60

i have update controller for whole row ...next one is i want to update specific column data help me please

here is my index.blade.php file

 @foreach ($banners as $banner) 
                        <tr>
                          <td>{{$banner->id}}</td>
                          <td>{{$banner->title}}</td>
                          <td>{{$banner->content}}</td>
                          <td> <img src="{{asset('/storage/'.$banner->image)}}" alt="" height="100px"></td>
                            <td>{{$banner->published_at}}</td>


                              @if ($banner->status=="active")
                              <td>
                                 <form action="{{route('?',$banner->id)}}" method="POST">
                                       @csrf
					  @if (isset($banner))
                                       @method('PUT')
                                           
                                       @endif
                                     <select name="status" id="">
                                        <option value="deactive" selected>{{$banner->status}}</option>
                                     </select>
                                     <br>
                                       <button type="submit" class=" btn btn-success btn-sm">Make deactive</button>
                           
                                 </form>
                            </td>
                            @else

                            <td>
                              <form action="{{route('?',$banner->id)}}" method="POST">
                                    @csrf
					  @if (isset($banner))
                                       @method('PUT')
                                           
                                       @endif
                                   
                                    <select name="status" id="">
                                       <option value="active" selected>{{$banner->status}}</option>
                                    </select>
                                    <br>
                                    <button type="submit" class=" btn btn-success btn-sm">Make active</button>
                        
                              </form>
                         </td>
                              @endif

                              <td>
                             <a href="{{route('banners.edit',$banner->id)}}" class="btn btn-add btn-sm" > <i class="fa fa-pencil"></i>  </a> 
                              <button type="submit" class="btn btn-danger btn-sm" onclick="handleDelete({{$banner->id}})" data-toggle="modal" data-target="#deleteModal">
                                <i class="fa fa-trash-o"></i>
                             </button>
                                 </td>
                        </tr>
                        @endforeach

my controller is

 public function index()
    {
        return view('banners.index')->with('banners',Banner::all());
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()

    
    { return view('banners.create');
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(BannerCreateRequest $request)
    {
        $image=$request->image->store('banners');
        Banner::create(['title'=>$request->title,'content'=>$request->content,'image'=>$image,'published_at'=>$request->published_at]);
        toastr()->success('Banner Created Successfully');
        return redirect(route('banners.index'));
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Banner $banner)
    {
        return view('banners.create')->with('banner',$banner);

        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(BannerUpdateRequest $request, Banner $banner)
     { 
          $data=$request->only(['title', 'content','published_at','status']);
          
        if($request->hasFile('image')){
            $image= $request->image->store('banners');
       
          $banner->delete_image();
            $data['image']=$image;
            }
        

         $banner->update($data);

         toastr()->success('Banner Updated Successfully');
         return redirect(route('banners.index'));   
        
        
        
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Banner $banner)
    {
        $banner->delete_image();
        $banner->delete();

        toastr()->success('Banner deleted Successfully');
         return redirect(route('banners.index'));

        //
    }

how can i make update functionality for make active and deactive

Please sign in or create an account to participate in this conversation.