How to save an image and retrieve it in view form in laravel

Posted 1 year ago by AbdulBazith

Guys i am working with a project.

i am having a form which asks details about vendor name, id, address and stores in db and the i viewed it in view.blade as tabular format.

Now i need to add image of the vendor too

How can i perform this?

i referred in google and some says to store in public folder, some says can directly store in db, some says just store the path in db.

which is better.

whats my objective is to get the image from the user and store it in DB and thenin view.blade to display the details as well as the image also

this is what my controller to get the details of the vendor,

 $this->validate($request,array(
        'vendor_id'=>'required',
         'vendor_name'=>'required|unique:vendor_details,vendor_name',
        'ven_loc'=>'required',
        'rate_per_litre'=>'required',
        'ven_area'=>'required',
        'ven_booth'=>'required',
        'vendor_phno'=>'required|integer',
        'vendor_address'=>'required',
        'note'=>'required'


       ));

       //inserting values

        $vendor_details=new vendor_details;

        $vendor_details->vendor_id = trim($request->vendor_id);
        $vendor_details->vendor_name=trim($request->vendor_name);
        $vendor_details->ven_loc=trim($request->ven_loc);
        $vendor_details->ven_area=trim($request->ven_area);
        $vendor_details->ven_booth=trim($request->ven_booth);
        $vendor_details->vendor_phno=trim($request->vendor_phno);
        $vendor_details->rate_per_litre=trim($request->rate_per_litre);
        $vendor_details->vendor_address=trim($request->vendor_address);
        $vendor_details->note=trim($request->note);

       $vendor_details->save();



         Session::flash('success',' Vendor Data Entered succesfully');

       return redirect()->route('Vendor_details.create' );


in this additionally i need to insert the image also

this is what my code in controller view.blade

  $ven = Vendor_details::orderBy('created_at','desc')->paginate(5);

         return view('Vendor_details.view')->withven($ven);


and this is what my view.blade

 <tbody>
            @foreach($ven as $vens)
                <tr>

                    <td>{{ $vens->vendor_name }}</td>
                    <td>{{ $vens->ven_loc }}</td>
                    <td>{{ $vens->ven_area }}</td>
                    <td>{{ $vens->ven_booth }}</td>
                    <td>{{ $vens->vendor_phno }}</td>
                    <td>{{ $vens->vendor_address }}</td>
                    <td>{{ $vens->rate_per_litre }}</td>
                    <td>{{ $vens->note }}</td>
</tr>
@endforeach 
</tbody>

Kindly some one help please

Please sign in or create an account to participate in this conversation.