Skip to content

Commit b76d828

Browse files
author
ahmadhuss
committed
feat: Added Vue.js component CategoriesCreate.vue
1 parent 1c0fce1 commit b76d828

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

resources/js/app.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ window.Vue = Vue;
1919
Vue.prototype._ = _;
2020
// id app
2121
Vue.component('front-page', require('./components/FrontPage.vue').default);
22+
23+
// id app
24+
let categoriesCreate = Vue.component('categories-create', require('./components/CategoriesCreate.vue').default);
25+
2226
// Load third party vue component `laravel-vue-pagination`
2327
Vue.component('pagination', require('laravel-vue-pagination'));
2428

2529
// load the front component
2630
new Vue({
27-
el: '#app'
31+
el: '#app',
32+
components: {
33+
categoriesCreate: categoriesCreate
34+
}
2835
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template>
2+
<div class="container py-5">
3+
<div class="row">
4+
<div class="col-lg-12">
5+
<div class="mb-3">
6+
<label for="name" class="form-label">Name:</label>
7+
<input type="text" v-model="name" name="name" class="form-control" id="name" placeholder="Category Name" autocomplete="off">
8+
<input type="button" class="btn btn-primary mt-3" value="Add Category" @click="createCategory()">
9+
</div>
10+
</div>
11+
</div>
12+
</div>
13+
</template>
14+
15+
<script>
16+
export default {
17+
name: 'CategoriesCreate',
18+
data: function (){
19+
return {
20+
name: ''
21+
}
22+
},
23+
methods: {
24+
createCategory: function (){
25+
console.log('Creating Category...');
26+
axios.post('/api/categories', {
27+
name: this.name
28+
}).then( function(response) {
29+
console.log('New Category ID', response.data.data.id);
30+
}).catch(function(err) {
31+
console.log('Category Route error Promise has been rejected!', err);
32+
});
33+
}
34+
}
35+
}
36+
</script>

resources/views/create.blade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@extends('master')
2+
3+
@section('vue')
4+
<div id="app">
5+
<categories-create></categories-create>
6+
</div>
7+
@endsection

routes/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616

1717
// Just load the Blade File
1818
Route::view('/', 'home');
19+
20+
// Categories create.blade.php file for the form creation.
21+
Route::view('/categories/create', 'create')->name('categories.create');

0 commit comments

Comments
 (0)