app/Http/Controllers/PortfolioController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Portfolio  $portfolio
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Portfolio $portfolio)
    {
        $this->authorize("update", Portfolio::class);
        $request->validate([
            "image" => ["required"],
            "photo_id" => ["required"]
        ]);
        if ($request->file('img') !== null) {
            Storage::disk("public")->delete("img/" . $portfolio->photo);
            $portfolio->photo= $request->file("img")->hashName();
            $request->file("img")->storePublicly("img", "public");
        }
        $portfolio->photo_id = $request->photo_id;
        $portfolio->save();
        return redirect()->route('portfolios.index');
    }
public function update ( Request $ request , Portfolio $ portfolio ) { $ this -> authorize ( " update " , Portfolio :: class ) ; $ request -> validate ( [ " image " => [ " required " ] , " photo_id " => [ " required " ] ] ) ; if ( $ request -> file ( 'img' ) !== null ) { Storage :: disk ( " public " ) -> delete ( " img/ " . $ portfolio -> photo ) ; $ portfolio -> photo = $ request -> file ( " img " ) -> hashName ( ) ; $ request -> file ( " img " ) -> storePublicly ( " img " , " public " ) ; } $ portfolio -> photo_id = $ request -> photo_id ; $ portfolio -> save ( ) ; return redirect ( ) -> route ( 'portfolios.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .