Skip to content

Commit f96a213

Browse files
committed
add user profile
1 parent fbe7e85 commit f96a213

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/User/Http/Controllers/UserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function create()
3333

3434
public function store(UserValidate $request)
3535
{
36-
$user = User::create($request->validated());
36+
User::create($request->validated());
3737

3838
return redirect()->route('user.index')
3939
->with('success', 'User created');

src/User/Http/Requests/UserValidate.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ public function rules()
1818
'name' => 'required',
1919
'email' => 'required|email',
2020
'password' => $this->passwordRules(),
21-
// 'profile_type' => '',
22-
// 'profile_id' => ''
23-
21+
'profile_type' => 'string',
22+
'profile_id' => 'integer|numeric',
2423
];
2524
}
2625

src/User/Models/User.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ protected static function newFactory()
3232
'name',
3333
'email',
3434
'password',
35+
'profile_type',
36+
'profile_id',
3537
];
3638

3739
/**
@@ -62,4 +64,9 @@ public function sendPasswordResetNotification($token)
6264
{
6365
$this->notify(new ResetPassword($token));
6466
}
67+
68+
public function profile()
69+
{
70+
return $this->morphTo();
71+
}
6572
}

stubs/resources/js/Pages/User/UserForm.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
</template>
4949

5050
<script setup>
51+
import { onMounted } from 'vue'
5152
import { useForm } from '@inertiajs/vue3'
5253
5354
import useTitle from '@/Composables/useTitle'
@@ -61,6 +62,20 @@ const props = defineProps({
6162
}
6263
})
6364
65+
onMounted(() => {
66+
if (
67+
isCreate.value &&
68+
route().params.profile_type &&
69+
route().params.profile_id
70+
) {
71+
form.transform((data) => ({
72+
...data,
73+
profile_type: route().params.profile_type,
74+
profile_id: route().params.profile_id
75+
}))
76+
}
77+
})
78+
6479
const breadCrumb = [
6580
{ label: 'Home', href: route('dashboard.index') },
6681
{ label: 'Users', href: route('user.index') },

0 commit comments

Comments
 (0)