After creating a component for form submission, I added another component for file uploads within it as shown below:
<booksmandala-originals-form
:action="'{{ url('admin/booksmandala-originals') }}'"
inline-template>
<form class="form-horizontal form-create" method="post" @submit.prevent="onSubmit" :action="this.action" enctype="multipart/form-data" novalidate>
@csrf
<div class="card-header">
<i class="fa fa-plus"></i> Create
</div>
<div class="card-body">
<div class="form-group row align-items-center" :class="{'has-danger':
errors.has('categories'), 'has-success': this.fields.published_by &&
this.fields.categories.valid }">
<label for="categories" class="col-form-label text-md-right"
:class="isFormLocalized ? 'col-md-4' : 'col-md-2'">Select
Categories</label>
<div :class="isFormLocalized ? 'col-md-4' : 'col-md-9 col-xl-8'">
<multiselect v-model="form.categories" tag-placeholder="Add this
as new category" placeholder="Search or add a category"
label="title" track-by="id" :options="{{ $categories->toJson()
}}" :multiple="true" :taggable="true" @tag="addCategory"
:close-on-select="false" name="categories[]"></multiselect>
<div v-if="errors.has('categories')" class="form-control-
feedback form-text" v-cloak>@{{ errors.first('categories') }}
</div>
</div>
</div>
<media-upload
:ref="'cover_uploader'"
:collection="'cover'"
:url="'{{ route('admin.upload.media', $folder) }}'"
:accepted-file-types="''"
:max-number-of-files="5"
:max-file-size-in-mb="100"
:accepted-file-types="''"
@if(isset($media))
:uploaded-images="{{ $media->toJson() }}"
@endif
</media-upload>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary" :disabled="submiting">
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
Save
</button>
</div>
</form>
</booksmandala-originals-form>
In the media-upload
component, there is a JSON variable called data
returned from the mentioned route. When submitting the main form, I want to capture that returned data in my controller.
The main Form (Booksmandala-original-form.js) contains the following code:
import AppForm from '../app-components/Form/AppForm';
Vue.component('booksmandala-originals-form', {
mixins: [AppForm],
data: function() {
return {
form: {
title: '' ,
body: '' ,
published_at: '' ,
enabled: false ,
slug : '',
categories:[],
tags: [],
files:[],
},
mediaCollections: ['cover'],
}
},
props : ['users','categories']
});
I aim to store the JSON value obtained from the media-upload
component into the data()
section of my form.js so that it can be utilized in my controller.