Bosstone
Bosstone

Reputation: 189

Laravel Code into Javascript?

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');

Upvotes: 0

Views: 63

Answers (1)

Serge
Serge

Reputation: 2187

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>

Upvotes: 2

Related Questions