8000 Implemented first phase of users CRUD · vs0uz4/l5vueka-laravel-vuejs@fe4f7fc · GitHub
[go: up one dir, main page]

Skip to content

Commit fe4f7fc

Browse files
committed
Implemented first phase of users CRUD
- Created users controller; - Added users CRUD routes; - Created users index view; - Created VdUsers vue component; - Registered VdUsers;
1 parent cbf0856 commit fe4f7fc

File tree

8 files changed

+266
-31
lines changed

8 files changed

+266
-31
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\User;
6+
use Illuminate\Http\Request;
7+
8+
class UsersController extends Controller
9+
{
10+
public function index()
11+
{
12+
$users = User::all();
13+
return view('users.index')->with(compact('users'));
14+
}
15+
16+
public function create()
17+
{
18+
19+
}
20+
21+
public function update()
22+
{
23+
24+
}
25+
26+
public function remove()
27+
{
28+
29+
}
30+
}

public/build/js/app-87b14f18f6.js renamed to public/build/js/app-efa76df45f.js

+52-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/rev-manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"css/app.css": "css/app-ad87f36536.css",
33
"css/vendor.css": "css/vendor-0634183a17.css",
4-
"js/app.js": "js/app-87b14f18f6.js"
4+
"js/app.js": "js/app-efa76df45f.js"
55
}

public/js/app.js

+52-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/js/app.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ require('bootstrap-sass')
66
import Vue from 'vue'
77

88
import PrimeiroComponente from './app/components/primeiro-componente.vue'
9+
import VdUsers from './app/users/main.vue'
910

1011
new Vue({
1112
el: '#app',
1213
components: {
13-
PrimeiroComponente
14+
PrimeiroComponente,
15+
VdUsers
1416
}
1517
})
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<script>
2+
export default {
3+
props: ['list'],
4+
data() {
5+
return {
6+
details: [],
7+
}
8+
},
9+
computed: {
10+
users () {
11+
return JSON.parse(this.list)
12+
},
13+
},
14+
methods: {
15+
toggle (id) {
16+
if (id === undefined) {
17+
this.toggleAll()
18+
} else {
19+
this.toggleOne(id)
20+
}
21+
},
22+
toggleAll () {
23+
if (this.details.length > 0) {
24+
this.details = []
25+
} else {
26+
this.details = this.users.map(user => user.id)
27+
}
28+
},
29+
toggleOne (id){
30+
if (this.details.includes(id)) {
31+
const index = this.details.indexOf(id)
32+
this.details.splice(index, 1)
33+
} else {
34+
this.details.push(id)
35+
}
36+
},
37+
}
38+
}
39+
</script>
40+
41+
<template>
42+
<div>
43+
<h1><i class="fa fa-w fa-users" aria-hidden="true"></i> Gerenciamento de Usuários</h1>
44+
<div class="well">
45+
<table class="table table-bordered table-striped">
46+
<thead>
47+
<tr>
48+
<th class="text-center">
49+
<a href="#" @click.prevent="toggle()">
50+
<i class="fa fa-fw" :class="{
51+
'fa-plus-circle red' : details.length === 0,
52+
'fa-minus-circle green' : details.length > 0
53+
}" aria-hidden="true"></i>
54+
</a>
55+
</th>
56+
<th>Nome</th>
57+
<th>E-mail</th>
58+
<th class="text-center">Data</th>
59+
<th class="text-center">Ações</th>
60+
</tr>
61+
</thead>
62+
<tbody v-for="user in users">
63+
<tr>
64+
<td class="text-center">
65+
<a href="#" @click.prevent="toggle(user.id)">
66+
<i class="fa fa-fw" :class="{
67+
'fa-plus-circle red' : !details.includes(user.id),
68+
'fa-minus-circle green' : details.includes(user.id)
69+
}" aria-hidden="true"></i>
70+
</a>
71+
</td>
72+
<td>{{ user.name }}</td>
73+
<td>{{ user.email }}</td>
74+
<td class="text-center">{{ user.created_at }}</td>
75+
<td class="text-center">
76+
<a href="#"><i class="fa fa-fw fa-pencil" aria-hidden="true"></i></a>
77+
<a href="#"><i class="fa fa-fw fa-trash-o" aria-hidden="true"></i></a>
78+
</td>
79+
</tr>
80+
<tr v-show="details.includes(user.id)">
81+
<td colspan="5">
82+
<i class="fa fa-fw fa-map-marker" aria-hidden="true"></i>Placeholder para Endereço
83+
</td>
84+
</tr>
85+
</tbody>
86+
</table>
87+
</div>
88+
</div>
89+
</template>
90+
91+
<style>
92+
.green {
93+
color: red;
94+
}
95+
.red {
96+
color: green;
97+
}
98+
</style>

resources/views/users/index.blade.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Bem Vindos ao Curso!</title>
9+
<link rel="stylesheet" href="{{ elixir('css/vendor.css') }}">
10+
<link rel="stylesheet" href="{{ elixir('css/app.css') }}">
11+
</head>
12+
<body>
13+
<div class="container" id="app">
14+
{{--<h1>Gerenciamento de Usuários</h1>
15+
<div class="well">
16+
{{ $users }}
17+
</div>--}}
18+
<vd-users list="{{ $users }}"></vd-users>
19+
</div>
20+
21+
<script src="{{ elixir('js/app.js') }}"></script>
22+
</body>
23+
</html>

routes/web.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
<?php
22

3-
/*
4-
|--------------------------------------------------------------------------
5-
| Web Routes
6-
|--------------------------------------------------------------------------
7-
|
8-
| Here is where you can register web routes for your application. These
9-
| routes are loaded by the RouteServiceProvider within a group which
10-
| contains the "web" middleware group. Now create something great!
11-
|
12-
*/
13-
143
Route::get('/', function () {
154
return view('welcome');
165
});
6+
7+
Route::group(['prefix' => 'usuarios'], function (){
8+
Route::get('', 'UsersController@index')->name('user.index');
9+
Route::post('criar', 'UsersController@create')->name('users.create');
10+
Route::post('atualizar/{id}', 'UsersController@update')->name('users.update');
11+
Route::get('remover/{id}', 'UsersController@remove')->name('users.remove');
12+
});

0 commit comments

Comments
 (0)
0