app/Http/Controllers/AcctController.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)
    {
         $this->validate($request, [
            'p_pix' => 'image|nullable|max:1999'
        ]);
        if ($request->hasFile('p_pix')) {
                $filenameWithExt = $request->file('p_pix')->getClientOriginalName();
                $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
                $extension = $request->file('p_pix')->getClientOriginalExtension();
                $fileNameToStore = $filename.'_'.time().'.'.$extension;
                $path = $request->file('p_pix')->storeAs('public/p_pixs', $fileNameToStore);
            }
            else {
                $user= Auth()->user();
                $fileNameToStore = $user->p_pix;
            }
         $acct = user::find($id);
         $acct->fname = $request['fname'];
        $acct->lname = $request['lname'];
        $acct->oname = $request['oname'];
        $acct->dob = $request['dob'];
        $acct->email = $request['email'];
        $acct->gender = $request['gender'];
            $acct->p_pix = $fileNameToStore;
       $user = Auth()->user();
         $acct->save(); 
         $data = [
            'success'=>'Account Updated',
            'user'=>$user,
            'accts'=> acct::orderBy('created_at', 'desc')->get()
        ];
        return  redirect('/store')->with($data);
    }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'p_pix' => 'image|nullable|max:1999' ] ) ; if ( $ request -> hasFile ( 'p_pix' ) ) { $ filenameWithExt = $ request -> file ( 'p_pix' ) -> getClientOriginalName ( ) ; $ filename = pathinfo ( $ filenameWithExt , PATHINFO_FILENAME ) ; $ extension = $ request -> file ( 'p_pix' ) -> getClientOriginalExtension ( ) ; $ fileNameToStore = $ filename . '_' . time ( ) . '.' . $ extension ; $ path = $ request -> file ( 'p_pix' ) -> storeAs ( 'public/p_pixs' , $ fileNameToStore ) ; } else { $ user = Auth ( ) -> user ( ) ; $ fileNameToStore = $ user -> p_pix ; } $ acct = user :: find ( $ id ) ; $ acct -> fname = $ request [ 'fname' ] ; $ acct -> lname = $ request [ 'lname' ] ; $ acct -> oname = $ request [ 'oname' ] ; $ acct -> dob = $ request [ 'dob' ] ; $ acct -> email = $ request [ 'email' ] ; $ acct -> gender = $ request [ 'gender' ] ; $ acct -> p_pix = $ fileNameToStore ; $ user = Auth ( ) -> user ( ) ; $ acct -> save ( ) ; $ data = [ 'success' => 'Account Updated' , 'user' => $ user , 'accts' => acct :: orderBy ( 'created_at' , 'desc' ) -> get ( ) ] ; return redirect ( '/store' ) -> with ( $ data ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//validation // 'body' => 'required|max:1000', // Get filename with the extension //get file name with the extension //get just extension //filename to store //upload image //create acct // if ($request->hasFile('p_pix')){ //     if($acct->p_pix != 'noimage.jpg'){ //         Storage::delete(['public/p_pixs/'. $acct->p_pix]); //     } //}  //     $acct->p_pix = $request['p_pix']; //    $file = $request->file('p_pix'); //    $filename = $request['fname'] .'-'.$user->id.'.jpg'; //    if ($file) { //        Storage::disk('local')->put($filename, File::get($file)); //    }