Skip to content

Commit f17f969

Browse files
Disable default Laravel JSON resource data wrapping
1 parent 378f1d4 commit f17f969

File tree

7 files changed

+51
-8
lines changed

7 files changed

+51
-8
lines changed

app/Http/Controllers/RoleController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function index()
2424
*/
2525
public function create()
2626
{
27-
//
27+
return Inertia::render('Roles/Create');
2828
}
2929

3030
/**
@@ -48,7 +48,9 @@ public function show(string $id)
4848
*/
4949
public function edit(string $id)
5050
{
51-
//
51+
$role = Role::findOrFail($id);
52+
53+
return Inertia::render('Roles/Edit', compact('role'));
5254
}
5355

5456
/**
@@ -64,6 +66,8 @@ public function update(Request $request, string $id)
6466
*/
6567
public function destroy(string $id)
6668
{
67-
//
69+
Role::destroy($id);
70+
71+
return back();
6872
}
6973
}

app/Providers/AppServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ public function register(): void
2020
*/
2121
public function boot(): void
2222
{
23+
JsonResource::withoutWrapping();
2324
}
2425
}

database/migrations/2014_10_12_000000_create_users_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function up(): void
2222
$table->foreignId('current_team_id')->nullable();
2323
$table->string('profile_photo_path', 2048)->nullable();
2424
$table->bigInteger('role_id')->unsigned()->index()->nullable();
25-
$table->foreign('role_id')->references('id')->on('roles')->cascadeOnDelete();
25+
// $table->foreign('role_id')->references('id')->on('roles')->cascadeOnDelete();
2626
$table->timestamps();
2727
});
2828

resources/js/Pages/Roles/Create.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
create component
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
10+
}
11+
</script>

resources/js/Pages/Roles/Edit.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div>
3+
<AppLayout title="Edit role">
4+
Edit role: {{ role.name }}
5+
</AppLayout>
6+
</div>
7+
</template>
8+
9+
<script>
10+
import AppLayout from '@/Layouts/AppLayout.vue';
11+
12+
export default {
13+
props: {
14+
role: Object,
15+
},
16+
components: { AppLayout }
17+
}
18+
</script>

resources/js/Pages/Roles/Index.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<template #header>
55
<h2 class="flex justify-between font-semibold text-xl text-gray-800 leading-tight">
66
Roles
7-
<inertia-link href="/roles/create">
7+
<inertia-link href="roles/create">
88
<a
99
class="text-sm border border-green-300 px-4 py-2 rounded-full text-green-600 hover:bg-green-600 hover:text-white hover:border-transparent mr-3 transition">Create
1010
role</a>
@@ -131,6 +131,14 @@ export default {
131131
},
132132
props: {
133133
roles: Object
134+
},
135+
methods: {
136+
deleteRole(role) {
137+
if (!confirm('Are you sure want to delete role?')) return;
138+
this.$inertia.delete(route('roles.destroy', role.id), {
139+
_token: this.$page.props.csrf_token,
140+
});
141+
},
134142
}
135143
}
136144
</script>

resources/js/app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ import './bootstrap';
22
import '../css/app.css';
33

44
import { createApp, h } from 'vue';
5-
import { createInertiaApp } from '@inertiajs/vue3';
5+
import { createInertiaApp, Link } from '@inertiajs/vue3';
66
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
77
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
88

9-
const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
9+
// const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
1010

1111
createInertiaApp({
1212
// title: (title) => `${title} - ${appName}`,
1313
resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
1414
setup({ el, App, props, plugin }) {
1515
return createApp({ render: () => h(App, props) })
1616
.use(plugin)
17+
.component('inertia-link', Link)
1718
.use(ZiggyVue, Ziggy)
1819
.mount(el);
1920
},
2021
progress: {
21-
color: '#4B5563',
22+
color: '#1266db',
2223
},
2324
});

0 commit comments

Comments
 (0)