Suju
Suju

Reputation: 1

displaying multiple images from database in laravel

i am new to laravel and i want to ask how to display multiple images that is located in the database.

i have already inserted images in my database through this code

here is my try.blade.php.

<h3>Upload Image</h3>
<form name="form" action="imageupload" method="POST" enctype="multipart/form- 
data">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<input type="file" name="img[]" multiple="true">
<br><br>
<input type="submit" name="ok" value="Upload">

</form>

@if(Session::has('msg'))
{{ Session::get('msg')}}
@endif

and here is my web.php

Route::get('imageup','userLog@imageup');
Route::post('imageupload','userLog@imageupup');

and here is my controller

public function imageup(){

    return view('try');
}

public function imageupup(Request $request){

        if($request->hasFile('img')){

                $image_array = $request->file('img');
                $array_len = count($image_array);
                for($i=0; $i<$array_len; $i++){

                    $image_size = $image_array[$i]->getClientSize();
                    $image_ext = $image_array[$i]->getClientOriginalExtension();

                    $new_image_name = rand(1234,9999).".".$image_ext;
                    $destination_path = public_path('/images');
                    $image_array[$i]->move($destination_path,$new_image_name);

                    $tab = new Tab1;
                    $tab->image_size = $image_size;
                    $tab->image_name = $new_image_name;
                    $tab->save();
                }

                return back()->with('msg','Images Uploade Successfully');
        }

        else{
            return back()->with('msg','Please choose any image file');
        }
}

this is the code in my table

Schema::create('tab1s', function (Blueprint $table) {
        $table->increments('id');
        $table->string('image_name');
        $table->string('image_size');
        $table->timestamps();
    });

i hope someone can help me.

Upvotes: 0

Views: 1204

Answers (1)

gotocartik
gotocartik

Reputation: 157

@foreach(json_decode($posts->images, true) as $images)
<div class="col-lg-2 col-md-2 col-sm-2">
    <a href="{{ URL::to('img/offers/'.$images)}}"
       class="portfolio-box">
        <img src="{{ URL::to('img/offers/'.$images)}}"
             class="img-responsive" alt="--">
        <div class="portfolio-box-caption">
            <div class="portfolio-box-caption-content">
            <span class="glyphicon glyphicon-zoom-in"
                  style="font-size: 80px"></span>
            </div>
        </div>
    </a>
</div> 
@endforeach

Upvotes: 1

Related Questions