Currently, I am using Vue within Laravel and facing an issue with retrieving data from a controller function that I am accessing. My goal is to use this data in the data()
section of my Vue template.
Though I am aware that the controller function returns the necessary data, I am unsure about how to handle the return/response in the axios call in order to effectively populate the data() function in Vue.
Below is the code snippet from the Blade/Vue template:
import moment from 'moment'
export default {
name: 'calendar',
data () {
return {
events: [
{
title: 'test',
allDay: true,
start: '2019-08-17',
},
],
config: {
defaultView: 'month',
eventRender: function(event, element) {
console.log(event)
}
},
}
},
created() {
this.fetchTasks();
},
methods: {
fetchTasks() {
axios.get('/landing/tasks' )
.then((response) => {
// handle success
this.assetOptions = response.data;
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
});
}
}
Regarding the Route:
Route::get('/landing/tasks', 'landingController@getTasks')
->name('landing/tasks');
And here is the Controller:
public function getTasks()
{
$getTask = Task::getTaskForLanding();
$result = array();
foreach($getTask as $id => $task){
$result[$task->task_id][] = $task;
}
}