app/Http/Controllers/Admin/BannerController.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, Banner $banner)
    {
        $data = $request->all();
        if($request->hasFile('image')) {
            if(!strpos($banner->image, 'http')) {
                Storage::delete(str_replace('storage', 'public', $banner->image));
            }
            $image = $request->file('image');
            $filename = str_random(28) . '.jpg';
            $path = 'public/banners/' . $filename;
            $file = Image::make($image->getRealPath())->encode('jpg',75);
            Storage::put($path, (string) $file);
            $data['image'] = Storage::url($path);
        }
        $banner->update($data);
        return response()->json([
            'status' => 'data edited'
        ], 200);
    }
public function update ( Request $ request , Banner $ banner ) { $ data = $ request -> all ( ) ; if ( $ request -> hasFile ( 'image' ) ) { if ( ! strpos ( $ banner -> image , 'http' ) ) { Storage :: delete ( str_replace ( 'storage' , 'public' , $ banner -> image ) ) ; } $ image = $ request -> file ( 'image' ) ; $ filename = str_random ( 28 ) . '.jpg' ; $ path = 'public/banners/' . $ filename ; $ file = Image :: make ( $ image -> getRealPath ( ) ) -> encode ( 'jpg' , 75 ) ; Storage :: put ( $ path , ( string ) $ file ) ; $ data [ 'image' ] = Storage :: url ( $ path ) ; } $ banner -> update ( $ data ) ; return response ( ) -> json ( [ 'status' => 'data edited' ] , 200 ) ; }
Update the specified resource in storage.
Update the specified resource in storage .