Skip to content

Commit 4297f6a

Browse files
committed
initial commit
1 parent 5174b1d commit 4297f6a

File tree

11 files changed

+349
-44
lines changed

11 files changed

+349
-44
lines changed

app/Http/Controllers/Auth/UserController.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function index()
3535

3636
/**
3737
* Store a newly created user in storage.
38-
*
38+
*
3939
* @param \Illuminate\Http\Request $request
4040
* @return \Illuminate\Http\JsonResponse
4141
*/
@@ -73,7 +73,7 @@ public function store(Request $request)
7373

7474
/**
7575
* Update the specified user in storage
76-
*
76+
*
7777
* @param \Illuminate\Http\Request $request
7878
* @param \App\Models\User $user
7979
* @return \Illuminate\Http\JsonResponse
@@ -82,10 +82,9 @@ public function update(Request $request, User $user)
8282
{
8383
$rules = [
8484
'name' => 'required|max:255',
85-
'email' => 'required|email:filter|max:255|unique:users',
85+
'email' => 'required|email:filter|max:255|unique:users,email,'.$user->id,
8686
'hobbies' => 'required',
8787
'phone' => 'required|digits:10',
88-
'password' => 'required|min:6',
8988
'country_id' => 'required'
9089
];
9190
$validator = Validator::make($request->all(), $rules);
@@ -101,7 +100,7 @@ public function update(Request $request, User $user)
101100
'email' => $request->email,
102101
'firstname' => $splitName[0],
103102
'lastname' => $splitName[1] ?? '',
104-
'hobbies' => $request->hobbies,
103+
'hobbies' => serialize($request->hobbies),
105104
'phone' => $request->phone,
106105
'country_id' => $request->country_id,
107106
'password' => bcrypt($request->password),
@@ -112,7 +111,7 @@ public function update(Request $request, User $user)
112111

113112
/**
114113
* Show the form for editing User
115-
*
114+
*
116115
* @param \App\Models\User $user
117116
* @return \Illuminate\Http\JsonResponse
118117
*/
@@ -123,7 +122,7 @@ public function show(User $user)
123122

124123
/**
125124
* Remove the specified user from storage.
126-
*
125+
*
127126
* @param \App\Models\User $user
128127
* @return \Illuminate\Http\JsonResponse
129128
*/

resources/js/components/Navbar.vue

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
<template>
2-
<nav class="navbar navbar-expand-lg navbar-light bg-white">
2+
<b-navbar v-if="user" type="light" variant="light">
33
<div class="container">
4-
<div id="navbarToggler" class="collapse navbar-collapse">
5-
<b-nav pills>
6-
<b-nav-item v-if="user" @click.prevent="logout">
7-
<b-link :to="{ name: 'login' }">
8-
Log Out
9-
</b-link>
10-
</b-nav-item>
11-
<template v-else>
12-
<b-nav-item>
13-
<b-link :to="{ name: 'login' }">
14-
Log In
15-
</b-link>
16-
</b-nav-item>
17-
<b-nav-item>
18-
<b-link :to="{ name: 'register' }">
19-
Register
20-
</b-link>
21-
</b-nav-item>
22-
</template>
23-
</b-nav>
24-
</div>
4+
<b-navbar-nav class="ml-2">
5+
<b-nav-item>
6+
<b-link :to="{name: 'users'}">
7+
Users
8+
</b-link>
9+
</b-nav-item>
10+
<b-nav-item>
11+
<b-link :to="{name: 'posts'}">
12+
Posts
13+
</b-link>
14+
</b-nav-item>
15+
</b-navbar-nav>
16+
<b-navbar-nav>
17+
<b-nav-item @click.prevent="logout" right>
18+
<b-link>
19+
Log Out
20+
</b-link>
21+
</b-nav-item>
22+
</b-navbar-nav>
2523
</div>
26-
</nav>
24+
</b-navbar>
2725
</template>
2826

2927
<script>

resources/js/middleware/guest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import store from '~/store'
22

33
export default (to, from, next) => {
44
if (store.getters['auth/check']) {
5-
next({ name: 'home' })
5+
next({ name: 'posts' })
66
} else {
77
next()
88
}

resources/js/pages/auth/login.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default {
5454
},
5555
5656
redirect () {
57-
this.$router.push({ name: 'home' })
57+
this.$router.push({ name: 'posts' })
5858
}
5959
}
6060
}

resources/js/pages/errors/404.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Page Not Found
55
</h3>
66
<div class="links">
7-
<router-link :to="{ name: 'home' }">
7+
<router-link :to="{ name: 'posts' }">
88
Go Home
99
</router-link>
1010
</div>

resources/js/pages/home.vue renamed to resources/js/pages/posts.vue

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
:reduce="author => author.id"
3131
:get-option-label="getOptionLabel">
3232
</v-select>
33-
<!-- class="p-0 form-control"-->
3433
<has-error
3534
:form="form"
3635
field="user_id" />
@@ -158,11 +157,16 @@
158157
Delete
159158
</b-button>
160159
</template>
160+
<template
161+
#cell(user)="data" >
162+
{{ data.value.name }}
163+
</template>
161164
</b-table>
162165
</b-card>
163166
</template>
164167

165168
<script>
169+
import axios from 'axios'
166170
import Form from "vform";
167171
import toast from '../mixins/message'
168172
@@ -173,7 +177,7 @@ export default {
173177
return {
174178
create_modal_show: false,
175179
edit_modal_show: false,
176-
fields: ['title', 'user_name', 'description', 'action'],
180+
fields: ['title', 'user', 'description', 'action'],
177181
items: [],
178182
authors: [],
179183
form: new Form({
@@ -194,35 +198,38 @@ export default {
194198
return (option && option.name) || ''
195199
},
196200
async loadAuth () {
197-
const { data } = await this.form.get('/api/users')
198-
this.authors = data;
201+
const { data } = await axios.get('/api/users')
202+
this.authors = data.data;
199203
},
200204
async loadPosts () {
201-
const { data } = await this.form.get('/api/posts')
202-
this.items = data;
205+
const { data } = await axios.get('/api/posts')
206+
this.items = data.data;
203207
},
204208
openModal(item_id) {
205209
let item = this.items.find(({id})=>id===item_id)
206210
this.edit_modal_show = true
207211
this.editform.id = item.id
208212
this.editform.title = item.title
209-
this.editform.user_id = item.user_id
213+
this.editform.user_id = item.user.id
210214
this.editform.description = item.description
211215
},
212216
async create_post() {
213217
const { data } = await this.form.post('/api/posts')
214-
if (data.id > 0)
218+
if (data.data.id > 0)
215219
{
216220
this.$show_message(`Notification`, 'The post was created successfully', 'success');
217221
this.create_modal_show = false;
218222
this.loadPosts();
223+
this.form.title = ""
224+
this.form.user_id = 0
225+
this.form.description = ""
219226
} else {
220227
this.$show_message(`Notification`, 'Post creating operation was failed', 'danger');
221228
}
222229
},
223230
async save_post() {
224231
const { data } = await this.editform.post('/api/posts/' + this.editform.id)
225-
if (data.id > 0)
232+
if (data.data.id > 0)
226233
{
227234
this.$show_message(`Notification`, 'The post was updated successfully', 'success');
228235
this.edit_modal_show = false;

resources/js/pages/users/create.vue

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<template>
2+
<div class="row">
3+
<div class="col-lg-8 m-auto">
4+
<b-card header="Create User">
5+
<b-form @submit.prevent="create" @keydown="form.onKeydown($event)">
6+
<b-form-group
7+
label="Name:"
8+
label-for="name">
9+
<b-form-input type="text" id="name" name="name" :class="{ 'is-invalid': form.errors.has('name') }" v-model="form.name"></b-form-input>
10+
<has-error :form="form" field="name" />
11+
</b-form-group>
12+
<b-form-group
13+
label="Hobbies:"
14+
label-for="hobbies">
15+
<v-select
16+
id="hobbies"
17+
v-model="form.hobbies"
18+
:searchable="true"
19+
:clearable="false"
20+
:multiple="true"
21+
:options="hobbies"
22+
:class="{ 'is-invalid': form.errors.has('hobbies') }"
23+
:reduce="hobbie => hobbie.value"
24+
label="text">
25+
</v-select>
26+
<has-error :form="form" field="hobbies" />
27+
</b-form-group>
28+
<b-form-group
29+
label="Email:"
30+
label-for="email" >
31+
<b-form-input type="email" id="email" name="email" :class="{ 'is-invalid': form.errors.has('email') }" v-model="form.email"></b-form-input>
32+
<has-error :form="form" field="email" />
33+
</b-form-group>
34+
<b-form-group
35+
label="Phone:"
36+
label-for="phone">
37+
<b-form-input :number="true" :formatter="formatPhone" type="text" id="phone" name="phone" :class="{ 'is-invalid': form.errors.has('phone') }" v-model="form.phone"></b-form-input>
38+
<has-error :form="form" field="phone" />
39+
</b-form-group>
40+
<b-form-group
41+
label="Country:"
42+
label-for="countries">
43+
<b-form-select id="countries" name="country_id" value-field="id" text-field="name" :class="{ 'is-invalid': form.errors.has('country_id') }" v-model="form.country_id" :options="countries"></b-form-select>
44+
<has-error :form="form" field="country_id" />
45+
</b-form-group>
46+
<b-form-group
47+
label="Password:"
48+
label-for="password" >
49+
<b-form-input type="password" id="password" name="password" :class="{ 'is-invalid': form.errors.has('password') }" v-model="form.password"></b-form-input>
50+
<has-error :form="form" field="password" />
51+
</b-form-group>
52+
<b-button type="submit" variant="primary">save</b-button>
53+
</b-form>
54+
</b-card>
55+
</div>
56+
</div>
57+
</template>
58+
59+
<script>
60+
import axios from 'axios'
61+
import Form from 'vform'
62+
63+
export default {
64+
components: {},
65+
66+
middleware: 'auth',
67+
68+
data: () => ({
69+
form: new Form({
70+
name: '',
71+
hobbies: [],
72+
email: '',
73+
phone: '',
74+
country_id: 1,
75+
password: ''
76+
}),
77+
hobbies: [
78+
{ value: 'Soccer', text: 'Soccer'},
79+
{ value: 'Game', text: 'Game'},
80+
{ value: 'Watching', text: 'Watching'}
81+
],
82+
countries: []
83+
}),
84+
85+
methods: {
86+
async create () {
87+
const { data } = await this.form.post('/api/users')
88+
this.$router.push({ name: 'users' })
89+
},
90+
async loadCountries () {
91+
const { data } = await axios.get('/api/countries')
92+
this.countries = data.data;
93+
},
94+
formatPhone(e){
95+
return String(e).substring(0,10);
96+
}
97+
},
98+
mounted() {
99+
this.loadCountries()
100+
}
101+
}
102+
</script>

0 commit comments

Comments
 (0)