Vue/Laravel - uploading a file on update doesn't work - laravel

I have a component that works on create form, but not on an update form. The image is being shown in the update form, but when I try to upload it, in the backend, I don't get any file for the field 'image'
This is the component:
<template>
<div>
<div v-if="!image">
<h2>Select an image</h2>
<input type="file" #change="onFileChange">
</div>
<div v-else>
<img :src="image" />
<input type="file" name="image" style="display:none">
<button #click="removeImage">Remove image</button>
</div>
</div>
</template>
<script>
export default {
props: {
image: {
type: String,
default: ""
}
},
data() {
return {
formData:new FormData(),
file: null
}
},
methods: {
onFileChange: function onFileChange(e) {
var files = e.target.files || e.dataTransfer.files;
if (!files.length)
return;
this.createImage(files[0]);
this.formData.append('file', files[0]);
this.file = files[0];
},
createImage: function createImage(file) {
var image = new Image();
var reader = new FileReader();
var vm = this;
reader.onload = function (e) {
vm.image = e.target.result;
};
reader.readAsDataURL(file);
},
removeImage: function removeImage(e) {
this.image = '';
}
}
}
</script>
And this is how I call it in the create view:
<image-upload></image-upload>
And this is for the update view:
<image-upload image="/uploads/{{ $magazine->image }}"></image-upload>
But, when I do dd($request->all()) in the update function in my controller I get this output:
array:8 [▼
"_method" => "PUT"
"_token" => "oNkMAyKsKsxOpqeonRDvyusqtFrfVgBEQOnyNrFw"
"image" => "1.png"
"name" => "Article name"
"summary" => ""
"visual_id" => ""
"spid_id" => ""
"files" => "1"
]
And for the create function where it actually works I get:
array:6 [▼
"_token" => "oNkMAyKsKsxOpqeonRDvyusqtFrfVgBEQOnyNrFw"
"name" => "Article name"
"summary" => ""
"visual_id" => ""
"spid_id" => ""
"image" => UploadedFile {#222 ▶}
]
This is the form:
{!! Form::model($magazine, ['method' => 'PUT', 'route' => ['magazines.update', 'id' => $magazine->id, 'files' => true]]) !!}
<div class="row magasin-form large-6 large-offset-3 columns">
<ul class="tabs">
<li class="tabs-title is-active">Tilbake</li>
</ul>
<div class="tabs-content">
<div class="tabs-panel is-active">
#section('errors')
#include('layouts.partials.errors')
#show
<p>Redigere</p>
<div class="row">
<div class="large-12 columns">
<label>Navn
{!! Form::text('name', $magazine->name, ['placeholder' => 'Navn']) !!}
</label>
</div>
</div>
<image-upload image="/uploads/{{ $magazine->image }}"></image-upload>
<div class="row">
<div class="large-12 columns">
<label>Visual ID
{!! Form::text('visual_id', $magazine->visual_id, ['placeholder' => 'Visual id']) !!}
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Spid ID
{!! Form::text('spid_id', $magazine->spid_id, ['placeholder' => 'spid id']) !!}
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Summary
{!! Form::textarea('summary', $magazine->name) !!}
</label>
</div>
</div>
<div class="row">
<div class="large-6 columns">
{!! Form::submit('Lagre', ['class'=> 'secondary button']) !!}
</div>
<div class="large-6 columns">
<a class="secondary hollow button" href="{{ route('magazines.index')}}">Avbryte</a>
</div>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
Updated
I have also tried with changing my component to this:
<template>
<div class="Image-input">
<div class="Image-input__input-wrapper">
<h2>+</h2>
<input #change="previewThumbnail" class="Image-input__input" name="thumbnail" type="file">
</div>
<div class="Image-input__image-wrapper">
<i v-show="! imageSrc" class="icon fa fa-picture-o"></i>
<img v-show="imageSrc" class="Image-input__image" :src="imageSrc">
</div>
</div>
</template>
<script>
export default {
props: ['imageSrc'],
methods: {
previewThumbnail: function(event) {
var input = event.target;
if (input.files && input.files[0]) {
var reader = new FileReader();
var vm = this;
reader.onload = function(e) {
vm.imageSrc = e.target.result;
}
reader.readAsDataURL(input.files[0]);
}
}
}
}
</script>
But I get the same output for my form on update.

It looks like you're accidentally passing the files boolean to the route array instead. Try updating your form opening to:
{!! Form::model($magazine, ['method' => 'PUT', 'route' => ['magazines.update', 'id' => $magazine->id], 'files' => true]) !!}

Your input field doesn't have a name so that might be why the form won't pick it up
Not sure why you are modifying the FormData. Any Reason you can't just submit the <input> with the form instead of extracting it?
Try showing us how the form looks, the place where you put your image-upload component

Related

Laravel livewire google recaptcha validation problem

I have a livewire component where i am trying to implement google recaptcha using a package https://github.com/anhskohbo/no-captcha. but getting validation error even when i complete the captcha validation process.
Below is my code livewire blade code.
<div class="col-md-6">
<div wire:ignore>
{!! NoCaptcha::renderJs() !!}
{!! NoCaptcha::display() !!}
</div>
</div>
<div class="form-inline justify-content-center text-center">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="far fa-envelope"></i></span>
</div>
<input type="email" class="form-control align-self-center" placeholder="Enter email" aria-label="newsletter_email" aria-describedby="basic-addon1" name="newsletter_email" wire:model.defer="newsletter_email">
</div>
<div class="form-group ml-3">
<button class="btn" style="background-color: #fff!important; color: #000!important;" wire:click.defer="newsletterEmail">SUBSCRIBE</button>
</div>
</div>
#error('recaptcha')
<div style="color: #fff">{{ $message }}</div>
#enderror
#error('newsletter_email')
<div style="color: #fff">{{ $message }}</div>
#enderror
#section('js')
<script type="text/javascript">
var onCallback = function () {
#this.set('recaptcha', grecaptcha.getResponse());
}
</script>
#endsection
and below is my validation code in livewire controller.
public $newsletter_email;
public $hascaptcha = 0;
public $captcha;
protected $rules = [
'newsletter_email' => 'required|email',
'recaptcha' => 'required|captcha',
];
protected $messages = [
'newsletter_email.required' => 'The Email Address cannot be empty.',
'newsletter_email.email' => 'The Email Address format is not valid.',
'recaptcha.required' => 'Please verify that you are not a robot.',
'recaptcha.captcha' => 'Captcha error! try again later or contact site admin.',
];
public function newsletterEmail()
{
$this->resetErrorBag();
$this->validate();
$current_date_time = Carbon::now()->toDateTimeString();
DB::table('news_letter')->insert([
'email' => $this->newsletter_email,
'created_at' => $current_date_time,
]);
$this->newsletter_email = "";
session()->flash('newsletter_message', 'Great!! You have subscribed for newsletter.');
}
No Package Needed...
Incase one needs Laravel Livewire - G Recaptcha V2,
In Your Component :-
<x-jet-form-section submit="submit(grecaptcha.getResponse(widgetId1))" method="POST">
<div class="col-span-6 sm:col-span-4"><div id="g-recaptcha"></div><x-jet-input-error for="g-recaptcha-response" class="mt-2" /></div>.
In Your Script :-
#section('scripts') <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer> </script> <script> var widgetId1; var onloadCallback = function() { widgetId1 = grecaptcha.render('g-recaptcha', { 'sitekey' : "{{ \Config::get('recaptcha.G_RECAPTCHA_SITE_KEY') }}", 'theme' : 'light' }); }; </script> #endsection
Your Component Class
public function submit($recaptcha)
Rest Of The Verification Code :-
`$url = 'https://www.google.com/recaptcha/api/siteverify';
$parameters = [
'secret' => \Config::get('recaptcha.G_RECAPTCHA_SITE_SECRET'),
'response' => $recaptcha
];
$qs = http_build_query($parameters);
$curl_request = "{$url}?{$qs}";
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_URL => $curl_request, CURLOPT_RETURNTRANSFER => 1));
$response = curl_exec($curl);
$responseData = json_decode($response);
curl_close($curl);
if($responseData->success){ }else{ throw ValidationException::withMessages(['g-recaptcha-response' => 'ReCaptcha validation failed.']); }`

I make Comment by Ajax but its not working

I make Comment by Ajax but its not working. It can insert and I already recived the data form controller. I check alert is display but html not display.
Here is my Route: Route::post('/addComment', 'LessonController#addComment');
Here is my controller
public function addComment(Request $request)
{
$lesson_id = $request->lesson_id;
$name = $request->name;
$body= $request->body;
$comment = new Comment();
$comment->name = $name ;
$comment->body = $body;
$comment->lesson_id = $lesson_id;
$comment->save();
return response()->json($comment);
}
Here is view comment create
<div class="leave_review">
<h3 class="blog_heading_border"> Leave a Comment </h3>
{!! Form::open(['action' => 'LessonController#addComment', 'method' => 'POST', 'id' => 'comment' ]) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="hidden" id="lesson_id" name="lesson_id" value="{{$lesson->id}}" />
</div>
<div class="row">
<div class="col-sm-6">
{{Form::label('name','Name')}}
{{Form::text('name', '', ['class' => 'form-group', 'id'=>'name']) }}
</div>
<div class="col-sm-12">
{{Form::label('body','Message')}}
{{Form::textarea('body', '', ['class' => 'form-group', 'id'=>'body']) }}
</div>
</div>
<div class="row">
<div class="col-md-12">
</div>
</div>
{{Form::submit('Submit', ['name'=>'submit', 'class' => 'mt_btn_yellow pull-right'])}}
{!! Form::close() !!}
<br>
Here is comment display view blade
<div id="commen_show">
#foreach ($comment as $item)
<ol class="review-lists">
<li class="comment">
<div class="activity_rounded">
<img src="/storage/Iconimage/about.png" alt="image"> </div>
<div class="comment-body">
<h4 class="text-left">{{$item->name}}
<small class="date-posted pull-right">{{$item->created_at}}</small>
</h4>
<p>{{$item->body}}</p>
Reply
<div class="clearfix"></div>
</div>
</li>
</ol>
#endforeach
</div>
</div>
Here is my javascript, I think something wrong with append
<script>
$(document).ready(function($){
$('#comment').on('submit', function(){
var lesson_id = $('#lesson_id').val();
var name = $('#name').val();
var body = $('#body').val();
var _token = $('input[name="_token"]').val();
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
url : "{{url('/addComment')}}", // the url where we want to POST
data: {_token:_token, lesson_id:lesson_id, body:body, name:name},
success: function(response) {
if(response){
$('#commnet_show').prepend(
` <ol class="review-lists">
<li class="comment">
<div class="activity_rounded">
<img src="/storage/Iconimage/about.png" alt="image"> </div>
<div class="comment-body">
<h4 class="text-left">${response.name}
<small class="date-posted pull-right">${response.created_at}</small>
</h4>
<p>${response.body}</p>
Reply
<div class="clearfix"></div>
</div>
</li>
</ol> `
;);
}
}
});
});
});
</script>

Sharing data between all Vue.js components

I'm building a CRUD web app using Laravel/Vue.js for the first time. I'm using a MySQL database and I used many Vue.js components, and each one can access a table in the database. Now I need to make some components to get data from other components to use it in a drop down, but I can't figure it out.
I tried using props but always get errors.
This is in the child vue:
<div class="form-group">
<select v-model="form.fabnom" type="text" name="fabnom" id="fabnom" class="form-control" :class="{ 'is-invalid': form.errors.has('fabnom') }">
<option v-for="fabriquant in fabriquants" :key="fabriquant.id" :value="fabriquant.fabnom">
</option>
</select>
<has-error :form="form" field="fabnom"></has-error>
</div>
<script>
export default {
data(){
return{
editmode: false,
machines :{},
form: new Form({
id:'',
code:'',
nom: '',
type:'',
serie:'',
date:'',
fabnom:'',
section:'',
unite:''
})
}
} ,
This is the API:
Route::apiResources([
'user' => 'API\UserController',
'fabriquant' => 'API\FabriquantController',
'machine' => 'API\MachineController',]);
Child controller(Parent one is nearly the same):
public function index()
{
//$this->authorize('isAdmin');
if (\Gate::allows('isAdmin')) {
return Machine::latest()->paginate(5);
}
}
public function store(Request $request)
{
$this->validate($request,[
'code' => 'required|string|max:191|unique:machines',
'nom' => 'required|string|max:191',
'type' => 'max:191',
'serie' => 'max:191',
'date' => 'max:191',
'fabnom' => 'max:191',
'section' => 'max:191',
'unite' => 'max:191',
]);
return Machine::create([
'code'=> $request['code'],
'nom'=> $request ['nom'],
'type'=> $request['type'],
'serie'=> $request['serie'],
'date'=> $request['date'],
'fabnom'=> $request['fabnom'],
'section'=> $request['section'],
'unite'=> $request['unite'],
]);
}
public function show($id)
{
//
}
public function update(Request $request, $id)
{
$machine = Machine::findOrFail($id);
$this->validate($request,[
'code' => 'required|string|max:191|unique:machines,code,'.$machine->id,
'nom' => 'max:191',
'type' => 'max:191',
'serie' => 'max:191',
'date' => 'max:191',
'fabnom' => 'max:191',
'section' => 'max:191',
'unite' => 'max:191',
]);
$machine->update($request->all());
return ['message' => 'Updated'];
}
public function destroy($id)
{
$machine = Machine::findOrFail($id);
// delete
$machine->delete();
return ['message' => 'Deleted'];
}
}
EDIT: You can see in the child component there is a string called fabnom and in the parent there is one also: so lets just say now I'm in the parent component and I added 3 items to its database via a modal each item has 6 columns in the database, one of them is called fabnom, now I passed to the child component page I opened an 'addNew' model and there is a dropdown box labeled fabnom which should have the 3 options that I already added I choose one of them and this value is going to be stored in the fabnom column of the database of the child component (I hope you get the idea guys)
This the parent.vue(The child one looks pretty the same the only difference that it has also a dropdown box in its 'addNew' model as mentioned up which is causing the problem):
<template>
<div class="container">
<div class="row mt-5" v-if="$gate.isAdmin()">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Liste des Fabriquants</h3>
<div class="card-tools">
<button class="btn btn-success" #click="newModal">
Ajouter</button>
</div>
</div>
<!-- /.card-header -->
<div class="card-body table-responsive p-0">
<table class="table table-hover">
<tbody>
<tr>
<th>Nom</th>
<th>Adresse</th>
<th>Téléphone</th>
<th>Fax</th>
<th>E-mail</th>
</tr>
<tr v-for="fabriquant in fabriquants.data" :key="fabriquant.id">
<td>{{fabriquant.fabnom}}</td>
<td>{{fabriquant.adresse}}</td>
<td>{{fabriquant.tel}}</td>
<td>{{fabriquant.fax}}</td>
<td>{{fabriquant.email}}</td>
<td>
<a href="#" #click="editModal(fabriquant)">
<i class="fa fa-edit"></i>
</a>
/
<a href="#" #click="deleteFabriquant(fabriquant.id)">
<i class="fa fa-trash"></i>
</a>
</td>
</tr>
</tbody></table>
</div>
<!-- /.card-body -->
<div class="card-footer">
<pagination :data="fabriquants" #pagination-change-page="getResults"></pagination>
</div>
</div>
<!-- /.card -->
</div>
</div>
<div v-if="!$gate.isAdmin()">
<not-found></not-found>
</div>
<!-- Modal -->
<div class="modal fade" id="Ajouter" tabindex="-1" role="dialog" aria-labelledby="AjouterLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" v-show="!editmode" id="AjouterLabel">Ajouter</h5>
<h5 class="modal-title" v-show="editmode" id="AjouterLabel">Modifier</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form #submit.prevent="editmode ? updateFabriquant() : createFabriquant()">
<div class="modal-body">
<div class="form-group">
<input v-model="form.fabnom" type="text" name="fabnom"
placeholder="Nom"
class="form-control" :class="{ 'is-invalid': form.errors.has('fabnom') }">
<has-error :form="form" field="fabnom"></has-error>
</div>
<div class="form-group">
<input v-model="form.adresse" type="text" name="adresse"
placeholder="Adresse"
class="form-control" :class="{ 'is-invalid': form.errors.has('adresse') }">
<has-error :form="form" field="adresse"></has-error>
</div>
<div class="form-group">
<input v-model="form.tel" type="text" name="tel"
placeholder="Téléphone"
class="form-control" :class="{ 'is-invalid': form.errors.has('tel') }">
<has-error :form="form" field="tel"></has-error>
</div>
<div class="form-group">
<input v-model="form.fax" type="text" name="fax"
placeholder="Fax"
class="form-control" :class="{ 'is-invalid': form.errors.has('fax') }">
<has-error :form="form" field="fax"></has-error>
</div>
<div class="form-group">
<input v-model="form.email" type="email" name="email"
placeholder="E-mail"
class="form-control" :class="{ 'is-invalid': form.errors.has('email') }">
<has-error :form="form" field="email"></has-error>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Fermer</button>
<button v-show="editmode" type="submit" class="btn btn-success">Modifier</button>
<button v-show="!editmode" type="submit" class="btn btn-primary">Ajouter</button>
</div>
</form>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data(){
return{
editmode: false,
fabriquants :{},
form: new Form({
id:'',
fabnom:'',
adresse: '',
tel:'',
fax:'',
email:''
})
}
},
methods: {
getResults(page = 1) {
axios.get('api/fabriquant?page=' + page)
.then(response => {
this.fabriquants = response.data;
});
},
updateFabriquant(){
this.$Progress.start();
// console.log('Editing data');
this.form.put('api/fabriquant/'+this.form.id)
.then(() => {
// success
$('#Ajouter').modal('hide');
Swal.fire(
'Modifié!',
'Informations modifiés!',
'success'
)
this.$Progress.finish();
Fire.$emit('AfterCreate');
})
.catch(() => {
this.$Progress.fail();
});
},
editModal(fabriquant){
this.editmode = true;
this.form.reset();
$('#Ajouter').modal('show');
this.form.fill(fabriquant);
},
newModal(){
this.editmode = false;
this.form.reset();
$('#Ajouter').modal('show');
},
deleteFabriquant(id){
Swal.fire({
title: 'Voulez vous vraiment supprimer cet fabriquant?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Oui, Supprimer!',
}).then((result) => {
// Send request to the server
if (result.value) {
this.form.delete('api/fabriquant/'+id).then(()=>{
Swal.fire(
'Supprimé!',
'Element supprimé.',
'success'
)
Fire.$emit('AfterCreate');
}).catch(()=> {
Swal.fire("Echec!", "Il y'a un problème.", "warning");
});
}
})
},
loadFabriquants(){
if(this.$gate.isAdmin()){
axios.get("api/fabriquant").then(({ data }) => (this.fabriquants = data));
}
},
createFabriquant(){
this.$Progress.start();
this.form.post('/api/fabriquant')
.then(()=>{
Fire.$emit('AfterCreate');
$('#Ajouter').modal('hide');
toast.fire({
type: 'success',
title: 'Fabriquant ajouté',
})
this.$Progress.finish();
})
.catch(()=>{
})
}
},
created() {
this.loadFabriquants();
Fire.$on('AfterCreate',()=>{
this.loadFabriquants();
});
}
}
</script>
If I understand your main issue, you could use something like an instance property or a javascript file to hold variables in client-side storage.
From what I understand, what you need is a way to first get data from your MySQL using one component, and then second, use that data in all the rest of your components. If so, I had this need with my current project about 2 months ago.
The only problem is that I'm not using Laravel/Vue but Vue.js, VueApollo, and GraphQL. Although, I'm pretty sure --and hope-- the way that I fixed my issue will only differ in syntax from the way you could solve yours.
I used a component to query some info from the user right after they log in.
Vue/Apollo Query
apollo: {
// Simple query that gets user info
me: {
query: gql` //GraphQL
{
me {
id
fullName
}
}
`,
loadingKey: "isLoading" //tracks results that are still loading.
}
}
Then I wanted to store the user's 'fullName' somewhere so that my navigation component could always use it. So I created a file:
src/config/credentialStore.js
In this file I created a displayName variable like this:
export const credentialStore = {
displayName: "",
userID: ""
};
Back in the component where I have the 'me' query, I destructured the data that was returned from the query with a function.
apollo: {
// Simple query that gets user info
me: {
query: gql`
{
me {
id
fullName
}
}
`,
loadingKey: "isLoading",
result({ data }) { //data is basically an object with the results of the query
this.$credentials.userId = data.me.id;
this.$credentials.displayName = data.me.fullName;
} //using this.$credentials.displayName will let me use that string from any component.
}
}
So you would do something like that and then maybe something like this:
<script>
export default {
data(){
return{
editmode: false,
fabriquants :{},
form: new Form({
id: this.$credentialStore.id,
fabnom:this.$credentialStore.fabnom, //what's a fabnom? 🤔
• • •
})
}
},
I hope this helps you or someone else.

'htmlentities() expects parameter 1 to be string, array given' error on Laravel view

I was testing the Request.php (submitting form with empty required fields) of my create view, and got the 'htmlentities() expects parameter 1 to be string, array given' error.
I know the error was generated because of the code below. This is a part of my view (calls javascript functions) used to create future appointment reminders.
I just don't see what is causing the error exactly.
<div style="display:none">
<div id="reminderiteminitial">
<div class="row" style="padding: 0.5em 0 0.5em 0.5em">
<div class="col-sm-2" >
{!! Form::text('reminder_time[]', 30, ['class' => 'form-control', 'placeholder' => '']) !!}
</div>
<div class="col-sm-2" >
{!! Form::select('reminder_timeunit[]', ['minute' => 'minutes(s)', 'hour' => 'hour(s)', 'day' => 'day(s)', 'week' => 'week(s)', 'month' => 'month(s)'], null, ['class' => 'form-control']) !!}
</div>
<div class="col-sm-2" >
{!! Form::select('delivery_method[]', ['eml' => 'Email'], null, ['class' => 'form-control']) !!}
</div>
<div class="col-sm-4" >
{!! Form::text('delivery_contact[]', null, ['class' => 'form-control', 'placeholder' => 'Your email address']) !!}
</div>
<div class="col-sm-2" >
<input class="btn btn-default" type="button" value="Delete reminder" onClick="removeitem(this);">
</div>
</div>
</div>
</div>
<div id="reminderitem">
</div>
<div class="row" style="padding: 1.5em 0 2.5em 0">
<div class="col-sm-12">
<input class="btn btn-default" type="button" value="Add a reminder" onClick="addreminderitem();">
</div>
</div>
Javascript:
<script language='javascript' type='text/javascript'>
var itemCount = 1;
var limit = 6;
function addreminderitem(){
if (itemCount == limit) {
alert("You have reached the maximum number of reminders.");
}
else {
var newreminderitem = document.getElementById('reminderitem');
var initialreminderitem_clone = document.getElementById('reminderiteminitial').cloneNode(true);
initialreminderitem_clone.id = 'item_'+itemCount++;
newreminderitem.appendChild(initialreminderitem_clone);
}
}
function removeitem(item){
item.parentNode.parentNode.parentNode.remove();
itemCount = itemCount - 1;
}
</script>
Whoops shows:
reminder_time
array:1 [
0 => "30"
]
reminder_timeunit
array:1 [
0 => "minute"
]
delivery_method
array:1 [
0 => "eml"
]
delivery_contact
array:1 [
0 => ""
]
Update #2
What's strange is that if I replace the following HTML forms code:
<div class="col-sm-2" >
{!! Form::text('reminder_time[]', 30, ['class' => 'form-control', 'placeholder' => '']) !!}
</div>
<div class="col-sm-2" >
{!! Form::select('reminder_timeunit[]', ['minute' => 'minutes(s)', 'hour' => 'hour(s)', 'day' => 'day(s)', 'week' => 'week(s)', 'month' => 'month(s)'], null, ['class' => 'form-control']) !!}
</div>
<div class="col-sm-2" >
{!! Form::select('delivery_method[]', ['eml' => 'Email'], null, ['class' => 'form-control']) !!}
</div>
<div class="col-sm-4" >
{!! Form::text('delivery_contact[]', null, ['class' => 'form-control', 'placeholder' => 'Your email address']) !!}
</div>
<div class="col-sm-2" >
<input class="btn btn-default" type="button" value="Delete reminder" onClick="removeitem(this);">
</div>
with the html it generates:
<div class="col-sm-2" >
<input class="form-control" placeholder="" name="reminder_time[]" type="text" value="30">
</div>
<div class="col-sm-2" >
<select class="form-control" name="reminder_timeunit[]"><option value="minute">minutes(s)</option><option value="hour">hour(s)</option><option value="day">day(s)</option><option value="week">week(s)</option><option value="month">month(s)</option></select>
</div>
<div class="col-sm-2" >
<select class="form-control" name="delivery_method[]"><option value="eml">Email</option></select>
</div>
<div class="col-sm-4" >
<input class="form-control" placeholder="Your email address" name="delivery_contact[]" type="text">
</div>
<div class="col-sm-2" >
<input class="btn btn-default" type="button" value="Delete reminder" onClick="removeitem(this);">
</div>
I don't get the error!?
Erorr
Your field names must be declared as string not as array:
<input name="reminder_time" />
instead of
<input name="reminder_time[]">`
Validating array
Or you can change your validation rules for array (https://laravel.com/docs/5.3/validation#validating-arrays):
$rules = [
'reminder_time.*' => 'unique',
],

MethodNotAllowedHttpException on Form Submission Stripe.js

I was experimenting with Stripe JS and got in some issues with this error. Following is my Route View & JS File. When i submit the post, it gives me the following error, MethodNotAllowedHttpException
Route
> Route::get('buy', function () {
> return view('buy'); });
JS File
$( document ).ready(function(){
var StripeBilling = {
init: function(){
this.form = $('.billing-form');
this.submitButton = this.form.find('input[type=submit]');
var stripeKey = $('meta[name="secret-key"]').attr('content');
Stripe.setPublishableKey(stripeKey);
this.bindEvents();
},
bindEvents: function () {
this.form.on('submit', $.proxy(this.sendToken, this));
},
sendToken: function (event) {
this.submitButton.val('One Moment');
Stripe.createToken(this.form, $.proxy(this.stripeResponseHandler, this));
event.preventDefault();
},
stripeResponseHandler: function(status, response){
console.log(status, response);
}
};
StripeBilling.init();
})
Default View
#section('content')
<div class="row">
<h1>Buy for $1</h1>
{!! Form::open(['id' => '#billing-form']) !!}
<div class="form-row">
<label>
<span>Card Number:</span>
<input type="text" data-stripe="number">
</label>
</div>
<div class="form-row">
<label>
<span>CVC:</span>
<input type="text" data-stripe="cvc">
</label>
</div>
<div class="form-row">
<label>
<span>Expiration:</span>
{!! Form::selectMonth(null , null, ['data-stripe' => 'exp-month']) !!}
{!! Form::selectYear(null, date('Y'),date('Y') + 10, null, ['data-stripe' => 'exp-year'] ) !!}
</label>
</div>
<div>
{!! Form::submit('submit') !!}
</div>
{!! Form::close() !!}
</div>
#stop
#section('footer')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://js.stripe.com/v2/"></script>
<script src="/js/billing.js"></script>
#stop
In your routes file you defined the path as a GET request but your form submission is doing a POST request either change your form to submit as a GET request or update your routes so it is a POST request

Resources