Commit 306cc544 authored by Ranie Santos's avatar Ranie Santos

update status list after form submission

parent 0681bdb6
......@@ -15,7 +15,7 @@ class StatusesController extends Controller
*/
public function index()
{
return Status::with('user')->get();
return Status::with('user')->latest()->get();
}
/**
......
......@@ -64,7 +64,7 @@ return [
|
*/
'timezone' => 'UTC',
'timezone' => 'Asia/Manila',
/*
|--------------------------------------------------------------------------
......
......@@ -5,13 +5,14 @@
</div>
<div class="message-body">
<form @submit.prevent="onSubmit">
<form @submit.prevent="onSubmit" @keydown="form.errors.clear()">
<p class="control">
<textarea class="textarea" placeholder="I have something to say..." v-model="form.body"></textarea>
<span class="help is-danger" v-if="form.errors.has('body')" v-text="form.errors.get('body')"></span>
</p>
<p class="control">
<button class="button is-primary">Submit</button>
<button class="button is-primary" :disabled="form.errors.any()">Submit</button>
</p>
</form>
</div>
......@@ -27,7 +28,9 @@
},
methods: {
onSubmit() {
this.form.post('http://localhost/laravel/vue2-laracasts-spa/public/statuses').then(status => alert('All done!'));
this.form
.post('http://localhost/laravel/vue2-laracasts-spa/public/statuses')
.then(status => this.$emit('completed', status));
}
}
}
......
......@@ -15,7 +15,7 @@
<div class="message-body" v-text="status.body"></div>
</div>
<add-to-stream></add-to-stream>
<add-to-stream @completed="addStatus"></add-to-stream>
</div>
</div>
</template>
......@@ -33,13 +33,26 @@
statuses: []
}
},
created() {
Status.all(statuses => this.statuses = statuses);
},
filters: {
ago(date) {
return moment(date).fromNow();
}
},
methods: {
addStatus(status) {
this.statuses.unshift(status);
window.scrollTo(0, 0);
alert('Status posted!');
}
}
}
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment