0

I have for displaying image from my directory.

I upload file in the public/uploads/images In the database, images are saved in my organigrammes tables in the profile_image field.

my Controller Here:

public function update(Request $request, Organigramme $organigramme)
{
// Check if a profile image has been uploaded
    if ($request->has('profile_image'))
    {
        $request->validate([
            'profile_image'            =>  'required|mimes:png,jpeg,jpg,svg:|max:2048'
        ]);
        // Get image file
        $image = $request->file('profile_image');
        // Make a image name based on organigramme matricule
        $name = str_slug($request->input('matricule'));
        // Define filePath
        $filePath = public_path('/uploads/images/');
        // Make a fileName [ name + file extension]
        $fileName = $name. '.' . $image->getClientOriginalExtension();
        // Upload image
        $extension = $image->getClientOriginalExtension();
        $image->move($filePath, $fileName);

        // Set organigramme profile image path in database to fileName
        $organigramme->profile_image = $fileName;
        $organigramme->save();
    }

    return view( 'admin.organigrammes.show', compact('organigramme'));
}

The code to display Image (view):

         <div class="panel panel-default" style="border-color: black">
            <div class="panel-heading" style="text-align: center;border-color: black">
            <b>  {{ $organigramme->prenoms }} {{ $organigramme->nom }}</b>
            </div>

            <form id="file-upload-form" class="uploader" action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
                @csrf
                <a href="#" onclick="document.getElementById('photoProfile').style.display='block'" class="">
                    <img src="{{ asset('public'.$organigramme->profile_image) }}" style="vertical-align: middle;width: 197px;height: 200px;border-radius: 5px;text-align: center;">
                </a>
            </form>
          <center> {{ $organigramme->date_de_naissance }}</center>
            @include('admin.organigrammes.profile')

        </div>
Saliou MBALO
  • 169
  • 1
  • 11

0 Answers0