Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

inertiajs/pingcrm

2292 stars
3 code files
View inertiajs/pingcrm on GitHub

composer.json

Open in GitHub
{
//
"require": {
"php": "^7.3|^8.0",
//
"inertiajs/inertia-laravel": "^0.4"
},
//
}

app/Http/Controllers/UsersController.php

Open in GitHub
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Request;
use Inertia\Inertia;
 
class UsersController extends Controller
{
public function index()
{
return Inertia::render('Users/Index', [
'filters' => Request::all('search', 'role', 'trashed'),
'users' => Auth::user()->account->users()
->orderByName()
->filter(Request::only('search', 'role', 'trashed'))
->get()
->transform(fn ($user) => [
'id' => $user->id,
'name' => $user->name,
'email' => $user->email,
'owner' => $user->owner,
'photo' => $user->photo_path ? URL::route('image', ['path' => $user->photo_path, 'w' => 40, 'h' => 40, 'fit' => 'crop']) : null,
'deleted_at' => $user->deleted_at,
]),
]);
}
//
}

resources/js/Pages/Users/Index.vue

Open in GitHub
<template>
<div>
<h1 class="mb-8 font-bold text-3xl">Users</h1>
<div class="mb-6 flex justify-between items-center">
<search-filter v-model="form.search" class="w-full max-w-md mr-4" @reset="reset">
<label class="block text-gray-700">Role:</label>
<select v-model="form.role" class="mt-1 w-full form-select">
<option :value="null" />
<option value="user">User</option>
<option value="owner">Owner</option>
</select>
<label class="mt-4 block text-gray-700">Trashed:</label>
<select v-model="form.trashed" class="mt-1 w-full form-select">
<option :value="null" />
<option value="with">With Trashed</option>
<option value="only">Only Trashed</option>
</select>
</search-filter>
<inertia-link class="btn-indigo" :href="route('users.create')">
<span>Create</span>
<span class="hidden md:inline">User</span>
</inertia-link>
</div>
<div class="bg-white rounded-md shadow overflow-x-auto">
<table class="w-full whitespace-nowrap">
<tr class="text-left font-bold">
<th class="px-6 pt-6 pb-4">Name</th>
<th class="px-6 pt-6 pb-4">Email</th>
<th class="px-6 pt-6 pb-4" colspan="2">Role</th>
</tr>
<tr v-for="user in users" :key="user.id" class="hover:bg-gray-100 focus-within:bg-gray-100">
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center focus:text-indigo-500" :href="route('users.edit', user.id)">
<img v-if="user.photo" class="block w-5 h-5 rounded-full mr-2 -my-2" :src="user.photo" />
{{ user.name }}
<icon v-if="user.deleted_at" name="trash" class="flex-shrink-0 w-3 h-3 fill-gray-400 ml-2" />
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('users.edit', user.id)" tabindex="-1">
{{ user.email }}
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('users.edit', user.id)" tabindex="-1">
{{ user.owner ? 'Owner' : 'User' }}
</inertia-link>
</td>
<td class="border-t w-px">
<inertia-link class="px-4 flex items-center" :href="route('users.edit', user.id)" tabindex="-1">
<icon name="cheveron-right" class="block w-6 h-6 fill-gray-400" />
</inertia-link>
</td>
</tr>
<tr v-if="users.length === 0">
<td class="border-t px-6 py-4" colspan="4">No users found.</td>
</tr>
</table>
</div>
</div>
</template>
 
<script>
import Icon from '@/Shared/Icon'
import pickBy from 'lodash/pickBy'
import Layout from '@/Shared/Layout'
import throttle from 'lodash/throttle'
import mapValues from 'lodash/mapValues'
import SearchFilter from '@/Shared/SearchFilter'
 
export default {
metaInfo: { title: 'Users' },
components: {
Icon,
SearchFilter,
},
layout: Layout,
props: {
filters: Object,
users: Array,
},
data() {
return {
form: {
search: this.filters.search,
role: this.filters.role,
trashed: this.filters.trashed,
},
}
},
watch: {
form: {
deep: true,
handler: throttle(function() {
this.$inertia.get(this.route('users'), pickBy(this.form), { preserveState: true })
}, 150),
},
},
methods: {
reset() {
this.form = mapValues(this.form, () => null)
},
},
}
</script>

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.