Flex's avatar
Level 4

How to add extra images upload buttons to the edit blade file?

I am working with Laravel 5.6 and mysql database. in my application I have vehicle data saving table and images saving table as uploads. relationship between Vehicle model and Upload model is like this, Vehicle Model

public function uploads()
    {
        return $this->hasMany(Upload::class);
    }

Upload Model

public function vehicle()
    {
        return $this->belongsTo(Vehicle::class);
    }

and uploads table structure is like this

id  filename  resized_name  original_name  vehicle_id
1   ddeerr        dfrerrerr            dfggdfgdfgdf          2
2   hyujjh        hyujkiolp           frtghyujnbff            5
3   frtghy        dfdfgdfgdf       dgddhdherere        6
4   dfgdfgd    sdsdgsdsds      sddgsgsgssgsg      6
5   xsdfgsd     hgfydiurio         jdkjfkjhkjfjdj           6

and I have vehicle table data edit link like this,

{{route('vehicles.edit',$vehicule->id.'/edit/')}}" >Edit</a>

when click some vehicle edit link the url is like this,

http://localhost:8000/myads/11/edit

and in vehicle edit form related images showing with following codes,

foreach( $vehicles-> uploads as $upload)

                    <img id="preview"
                         src="{{asset((isset($upload) && $upload->resized_name!='')?'images/'.$upload->resized_name:'images/noimage.png')}}"
                         height="200px" width="200px"/>
                    <input class="form-control" style="display:none" name="files[]" type="file" id="files" name="_token" value="{{ csrf_token() }}" enctype="multipart/form-data">
                    <br/>

               <a href="/myads/{{$upload->id}}/editimage">Edit Image</a>|

               <a class="button is-outlined" href="/myads/{{$upload->id}}/delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>

                  <hr>
                   @endforeach
                    @endif

now my problem is coming, actually in my application user can only upload images 4images related each vehicle. in new vehicle data submission form user has facility to attach up to 1-4 images. then assuming one user who has attached only two images when he insert new vehicle data record. but after he needed attach more 2 images with his vehicle advertisement. then he should go edit form and he can seen existing his attach two images file and there should be two attach buttons to attach new two images. how can do this, I think we should check uploads table with related vehicle_id and if there are 4 images then he cannot attach another images and if there are images less then 4 user can attach images up to 4 images in upload table. how can I display images upload buttons?

0 likes
1 reply
Flex's avatar
Level 4

No, any solutions here...

Please or to participate in this conversation.