0

I am using dropzone.js in my Laravel App to upload images. The Code looks like this:

<script>
Dropzone.options.myDropzone = {
    paramName: 'file',
    maxFilesize: 5, // MB
    maxFiles: 20,
    acceptedFiles: ".jpeg,.jpg,.png,.gif",
};
</script>

I want to make "maxFiles" more dynamic and load it with data from database. I have a table "cat" where field "count" is populated with a number. I can show the number using

$cat->count

I tried with

maxFiles: $cat->count - not working
maxFiles: {{ $cat->count }} - not working

Can someone advice me how to solve this issue?

Kind Regards,

Stefan

Update:

This Lines have been updated as they are indeed important. It looks like, that the Javascript will never be called:

 <form data-count= "{{ $cats->count }}" action="{{ route('upload') }}" enctype="multipart/form-data" class="dropzone" id="fileupload" method="POST">
        @csrf
        {{ Form::hidden('cat_id', $cats->id) }}
        <div class="fallback">
          <input name="file" type="files" multiple accept="image/jpeg, image/png, image/jpg" />
        </div>
      </form>

The Route:

 Route::post('upload' , 'ProjectController@upload')->name('upload');
8
  • you write this code in a JavaScript file or in blade.php? Commented May 26, 2018 at 20:09
  • one way is to query the db using an ajax call, and update the maxfiles, you cant simply paste php code in javascript Commented May 26, 2018 at 20:11
  • @Dry7: the Javascript Code is in the blade.php Commented May 26, 2018 at 20:11
  • @Shobi: oh, I see Commented May 26, 2018 at 20:12
  • try to see what happens with this {{ dd($cat->count) }} Commented May 26, 2018 at 20:14

1 Answer 1

2

Does this work? It should... wonder if it's the definition of the annonimous object that mixes it up...

<script>
var max = {{ $cat->count }};
Dropzone.options.myDropzone = {
    paramName: 'file',
    maxFilesize: 5, // MB
    maxFiles: max,
    acceptedFiles: ".jpeg,.jpg,.png,.gif",
};
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Dear Serge, thank you for your Feedback. I have found the same code on another site, so it should work - but it looks like, that my Javascript Code never will be called - I have updated the original Code...

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.