app/Http/Controllers/PartController.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(int $partID, Request $request, Parts $parts)
    {
        $part = Parts::find($partID);
        $request->validate([
            'name' => 'required',
            'price' => 'required',
            'stock' => 'required',
        ]);
        $input = $request->all();
        if ($image = $request->file('image')) {
            $destinationPath = 'image/';
            $profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
            $image->move($destinationPath, $profileImage);
            $input['image'] = "$profileImage";
            $part->update(['image' => $profileImage]);
        }
        $part->update($input);
        return redirect()->route('parts.index')->with('status', 'Part updated');
    }
public function update ( int $ partID , Request $ request , Parts $ parts ) { $ part = Parts :: find ( $ partID ) ; $ request -> validate ( [ 'name' => 'required' , 'price' => 'required' , 'stock' => 'required' , ] ) ; $ input = $ request -> all ( ) ; if ( $ image = $ request -> file ( 'image' ) ) { $ destinationPath = 'image/' ; $ profileImage = date ( 'YmdHis' ) . " . " . $ image -> getClientOriginalExtension ( ) ; $ image -> move ( $ destinationPath , $ profileImage ) ; $ input [ 'image' ] = " $ profileImage " ; $ part -> update ( [ 'image' => $ profileImage ] ) ; } $ part -> update ( $ input ) ; return redirect ( ) -> route ( 'parts.index' ) -> with ( 'status' , 'Part updated' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .