Home > Mobile >  Image does not displayed - How to display an image perhaps dynamically
Image does not displayed - How to display an image perhaps dynamically

Time:06-17

I would like to display an employee picture using the url as shown below which I think should work but not. However it does work with the second url which is static. why is this happening?

This the first url that does not work

  <img id="message" src="{{url('/profile_picture/' . $employee->picture)}}"   style="width: 150px;"/>

This is the second url that does work

  <img id="message" src="{{url('/profile_picture/20220615232745.jpg')}}"   style="width: 150px;"/>

To save a picture I use the following method

public function ProfileStore(Request $request)
{
    $data = User::find(Auth::user()->id);
    $data->name =$request->name;
    $data->email =$request->email;   
   
     if ($request->file('picture')) {
        $file = $request->file('picture');
        $filename = date('YmdHis') . "." .  $file->getClientOriginalExtension();
         $file->move('profile_picture/',  $filename);
         $data['picture'] = " $filename";
     }
 
     $data->save();

   
    return redirect()->route('profile.index');
}

The route

Route::post('/people/employees/profiles/store', [ProfileController::class, 'ProfileStore'])->name('profile.store');

Route::get('/people/employees/profiles/edit/{id}', [ProfileController::class, 'ProfileEdit'])->name('profile.edit');

My edit method

 public function ProfileEdit()
{
    $id = Auth::user()->id;
    $employee = User::find($id);
 
    return view('fms.people.employee.profiles.profile_edit')->with('employee',$employee);
}

CodePudding user response:

in you profilestore function, when setting the $filename to $data['picture'], you have extra space before it.Remove that space and try again. For ex:

if ($request->file('picture')) {
    $file = $request->file('picture');
    $filename = date('YmdHis') . "." .  $file->getClientOriginalExtension();
     $file->move('profile_picture/',  $filename);
     $data['picture'] = "$filename";
 }
  • Related