Skip to content

Commit 3d0b617

Browse files
Finish adding a new role functionality
1 parent 444f0d2 commit 3d0b617

File tree

5 files changed

+99
-11
lines changed

5 files changed

+99
-11
lines changed

app/Http/Controllers/RoleController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Http\Requests\RoleStoreRequest;
56
use App\Http\Resources\RoleResource;
67
use App\Models\Role;
78
use Illuminate\Http\Request;
@@ -30,9 +31,12 @@ public function create()
3031
/**
3132
* Store a newly created resource in storage.
3233
*/
33-
public function store(Request $request)
34+
public function store(RoleStoreRequest $request)
3435
{
35-
//
36+
$validatedData = $request->validated();
37+
Role::create($validatedData);
38+
39+
return redirect()->route('roles.index')->with('success', 'Role has been created!');
3640
}
3741

3842
/**
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class RoleStoreRequest extends FormRequest
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*/
12+
public function authorize(): bool
13+
{
14+
return true;
15+
}
16+
17+
/**
18+
* Get the validation rules that apply to the request.
19+
*
20+
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
21+
*/
22+
public function rules(): array
23+
{
24+
return [
25+
'name' => 'required|max:255',
26+
];
27+
}
28+
}

database/migrations/2014_10_12_000000_create_users_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function up(): void
1717
$table->string('name', 255);
1818
$table->string('email', 255)->unique();
1919
$table->text('description')->default('Some description');
20-
$table->string('avatar', 50)->default('placeholder');
20+
$table->string('avatar', 255)->default('placeholder');
2121
$table->string('password', 255);
2222
$table->rememberToken();
2323
$table->foreignId('current_team_id')->nullable();

resources/js/Pages/Roles/Create.vue

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
11
<template>
2-
<div>
3-
create component
4-
</div>
5-
</template>
2+
<AppLayout title="Create role">
3+
<template #header>
4+
<h2 class="text-xl font-semibold leading-tight text-gray-800">
5+
Create role
6+
</h2>
7+
</template>
8+
9+
<div class="py-12">
10+
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
11+
<div class="w-full max-w-xs m-auto">
12+
<form @submit.prevent="submit" class="px-8 pt-6 pb-8 m-auto mb-4 bg-white rounded shadow-md"
13+
enctype="multipart/form-data">
14+
<div class="mb-4">
15+
<label class="block mb-2 text-sm font-bold text-gray-700" for="name">
16+
Role name <span class="text-red-500">*</span>
17+
</label>
18+
<input v-model="form.name"
19+
class="w-full px-3 py-2 mb-2 leading-tight text-gray-700 border rounded shadow appearance-none focus:outline-none focus:shadow-outline"
20+
id="name" type="text" />
21+
<span class="text-red-500">{{ errors.name }}</span>
22+
</div>
23+
24+
<div class="flex items-center justify-between">
25+
<Button :form="form"></Button>
26+
</div>
27+
</form>
628

29+
<p class="text-xs text-center text-gray-500">
30+
&copy;2023 -
31+
<a class="text-blue-500" href="https://github.com/perisicnikola37"
32+
target="_blank">@perisicnikola37</a>
33+
</p>
34+
</div>
35+
</div>
36+
</div>
37+
</AppLayout>
38+
</template>
39+
740
<script>
8-
export default {
41+
import Button from '@/Components/Button.vue';
42+
import AppLayout from '@/Layouts/AppLayout.vue';
943
10-
}
11-
</script>
44+
export default {
45+
components: {
46+
AppLayout,
47+
Button
48+
},
49+
props: {
50+
errors: Object
51+
},
52+
data() {
53+
return {
54+
form: this.$inertia.form({
55+
name: '',
56+
})
57+
};
58+
},
59+
methods: {
60+
submit() {
61+
this.form.post(this.route('roles.store'), {
62+
});
63+
}
64+
}
65+
};
66+
</script>
67+

resources/js/Pages/Users/Create.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
</template>
8989

9090
<script>
91-
import AppLayout from '@/Layouts/AppLayout.vue';
9291
import Button from '@/Components/Button.vue';
92+
import AppLayout from '@/Layouts/AppLayout.vue';
9393
9494
export default {
9595
components: {

0 commit comments

Comments
 (0)