I'm at a loss trying to figure out a solution for this issue. My current task involves editing a pub schedule using an edit form:
pubs/UpdateProfile.vue
<template>
<confirm title="Edit Pub" ok="Save pub" :show="show"
v-on:save="save"
v-on:close="close">
<div class="field">
<label class="label">Name</label>
<div class="control">
<input class="input" type="text" placeholder="Pub name" v-model="data.name">
</div>
</div>
<!-- Other fields and functionalities omitted for brevity -->
</confirm>
<script>
import Pub from "../../models/pub";
export default {
data() {
return {
selected: null,
data: new Pub(),
}
},
props: {
show: Boolean,
data: Object,
},
computed: {
},
methods: {
save() {
this.$emit('save', this.data);
},
close() {
this.$emit('close');
},
// Functionality methods omitted for brevity
updateOpeningTime(schedule){
this.api.put('/pubschedules/' + this.data.id + '/' + schedule).then(response => {
this.data = response.data;
});
},
}
}
}
In my controller:
PubsController.php
public function updateOpeningTime(Pub $pub)
{
json_die("Hola");
json_die($pub->id);
Schedule::where(['pub_id', $pub->id])->update(['opening_time' => request()->all()]);
}
pub.js
export default class Pub {
constructor() {
this.id = null;
this.name = null;
this.schedulesDisplayed = null;
}
};
schedulesDisplayed is sourced from a relation between Pub and Schedule models (pubSchedules: 1pub x N schedules):
/**
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getSchedulesDisplayedAttribute()
{
return $this->pubSchedules()->get();
}
Upon clicking the Save button post-editing, I can see the "Hola" message invoked in the controller. However, I encounter errors preventing further development with the following error messages:
app.js:56802 [Vue warn]: Error in render: "TypeError: Cannot read property 'name' of undefined"
found in
---> <UpdateProfile> at
resources/assets/js/components/pubs/UpdateProfile.vue
<Pubs> at resources/assets/js/components/Pubs.vue
<Root>
The error points towards a 'name' property that seems to be missing or improperly referenced. Any insights into resolving this issue will be greatly appreciated.