Skip to content

Commit 0db1b44

Browse files
committed
User Index page works
1 parent 3b1f1ff commit 0db1b44

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

resources/js/Pages/Users/Index.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<option value="only">Only Trashed</option>
1717
</select>
1818
</search-filter>
19-
<inertia-link class="btn-indigo" :href="route('users.create')">
19+
<inertia-link class="btn-indigo" href="`/users/add`">
2020
<span>Create</span>
2121
<span class="hidden md:inline">User</span>
2222
</inertia-link>
@@ -32,7 +32,7 @@
3232
<td class="border-t">
3333
<inertia-link
3434
class="px-6 py-4 flex items-center focus:text-indigo-500"
35-
:href="route('users.edit', user.id)"
35+
:href="`/users/edit/${user.id}`"
3636
>
3737
<img v-if="user.photo" class="block w-5 h-5 rounded-full mr-2 -my-2" :src="user.photo" />
3838
{{ user.name }}
@@ -46,7 +46,7 @@
4646
<td class="border-t">
4747
<inertia-link
4848
class="px-6 py-4 flex items-center"
49-
:href="route('users.edit', user.id)"
49+
:href="`/users/edit/${user.id}`"
5050
tabindex="-1"
5151
>
5252
{{ user.email }}
@@ -55,14 +55,14 @@
5555
<td class="border-t">
5656
<inertia-link
5757
class="px-6 py-4 flex items-center"
58-
:href="route('users.edit', user.id)"
58+
:href="`/users/edit/${user.id}`"
5959
tabindex="-1"
6060
>
6161
{{ user.owner ? 'Owner' : 'User' }}
6262
</inertia-link>
6363
</td>
6464
<td class="border-t w-px">
65-
<inertia-link class="px-4 flex items-center" :href="route('users.edit', user.id)" tabindex="-1">
65+
<inertia-link class="px-4 flex items-center" :href="`/users/edit/${user.id}`" tabindex="-1">
6666
<icon name="cheveron-right" class="block w-6 h-6 fill-gray-400" />
6767
</inertia-link>
6868
</td>
@@ -106,8 +106,11 @@ export default {
106106
watch: {
107107
form: {
108108
handler: throttle(function () {
109-
let query = pickBy(this.form);
110-
this.$inertia.replace(this.route('users', Object.keys(query).length ? query : { remember: 'forget' }));
109+
let query = Object.keys(pickBy(this.form)).length ? pickBy(this.form) : { remember: 'forget' };
110+
111+
this.$inertia.replace(`/users`, {
112+
'data': query
113+
});
111114
}, 150),
112115
deep: true,
113116
},

src/Controller/UsersController.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ class UsersController extends AppController
1919
*/
2020
public function index()
2121
{
22-
$this->paginate = [
23-
'contain' => ['Accounts'],
22+
$filters = [
23+
'search' => $this->getRequest()->getQuery('search') ?? '',
24+
'role' => $this->getRequest()->getQuery('role') ?? '',
25+
'trashed' => $this->getRequest()->getQuery('trashed') ?? '',
2426
];
25-
$users = $this->paginate($this->Users);
2627

27-
$this->set(compact('users'));
28+
$users = $this->Users->find()->where([
29+
'account_id' => $this->getRequest()->getAttribute('identity')->get('account_id')
30+
])->toArray();
31+
32+
33+
$this->set(compact('users', 'filters'));
2834
}
2935

3036
/**

src/Model/Entity/User.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,21 @@ class User extends Entity
5151
protected $_hidden = [
5252
'password',
5353
];
54+
55+
/**
56+
* Virtual fields.
57+
*
58+
* @var array
59+
*/
60+
protected $_virtual = ['name'];
61+
62+
/**
63+
* Name virtual field.
64+
*
65+
* @return string
66+
*/
67+
protected function _getName()
68+
{
69+
return $this->first_name . ' ' . $this->last_name;
70+
}
5471
}

0 commit comments

Comments
 (0)