0

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.

1 Answer 1

1
@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
Sign up to request clarification or add additional context in comments.

1 Comment

hi..im sorry but where do you get $posts in this code? thank you for your answer and also the images? im sorry , im new to laravel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.