app/Http/Controllers/ProfilesController.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,[
       'name' => 'required',
       'email' => 'required',
    ]);
    if($request->hasFile('slika'))
    {
      $fileNameWithExt = $request->file('slika')->getClientOriginalName();
      $filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
      $extension = $request->file('slika')->getClientOriginalExtension();
      $fileNameToStore = $filename.'_'.time().'.'.$extension;
      $path = $request->file('slika')->storeAs('public/slike',$fileNameToStore);
    }
    $user = User::find($id);
    $user->name = $request->input('name');
    $user->email = $request->input('email');
    if($request->hasFile('slika')){
      $user->slika=$fileNameToStore;
    }
    $user->save();
    return redirect('/profile')->with('success', 'Profile Updated');
    }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'name' => 'required' , 'email' => 'required' , ] ) ; if ( $ request -> hasFile ( 'slika' ) ) { $ fileNameWithExt = $ request -> file ( 'slika' ) -> getClientOriginalName ( ) ; $ filename = pathinfo ( $ fileNameWithExt , PATHINFO_FILENAME ) ; $ extension = $ request -> file ( 'slika' ) -> getClientOriginalExtension ( ) ; $ fileNameToStore = $ filename . '_' . time ( ) . '.' . $ extension ; $ path = $ request -> file ( 'slika' ) -> storeAs ( 'public/slike' , $ fileNameToStore ) ; } $ user = User :: find ( $ id ) ; $ user -> name = $ request -> input ( 'name' ) ; $ user -> email = $ request -> input ( 'email' ) ; if ( $ request -> hasFile ( 'slika' ) ) { $ user -> slika = $ fileNameToStore ; } $ user -> save ( ) ; return redirect ( '/profile' ) -> with ( 'success' , 'Profile Updated' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//Dohvaćanje filename-a sa extenzijom //Dohvati samo $fileName //dohvati samo ekstenziju //Ime za pohranu //Upload slike