How to Create a custom field select (1-n relationship) with livewire #580
christmex
started this conversation in
Tips & Tricks
Replies: 1 comment 1 reply
-
I love it! Thanks a lot for sharing this @christmex . As you said, this can probably be improved quite a bit:
Then it's fewer steps. I'll ask @phpfour to take another look at this soon, when we develop some accessory Livewire components. We can improve it then 💪 Thanks again @christmex ! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
*note :
Hi there, in this tutorial, I'm about to share with you guys how to make a "Custom field select (1-n relationship) with livewire" in backpackforlaravel, actually backpack already provides select2 with their backpack pro 🤩, but let's just assume that we don't have backpack pro for now, and we really love to use livewire, here's what I did, without any further ado let's begin.
Steps
Step 0. Preparation
Let's install the livewire, open your terminal and slap this command
Step 1. Create our custom create and edit blade
create a new file placed in
resources/views/vendor/backpack/crud/create.blade.php
and put this codethe point is, we want to add the livewire assets, anyways, livewire v3, will launch very soon, so maybe we don't need to do this anymore, also what I know backpack will support livewire in this V6, so let's see how it goes, cant wait for it.
okay next we create a new file placed in
resources/views/vendor/backpack/crud/edit.blade.php
and put this codeStep 2. Create our livewire component
Use this command
then let's open the blade file
resources/views/livewire/fields/livewire-select.blade.php
, and put this codethen open the
app/Http/Livewire/Fields/LivewireSelect.php
and replace all code with this codeStep 3. Create our custom backpack field
Use this command
After that let's open that file, usually placed in
resources/views/vendor/backpack/crud/fields/
, and rewrite the code with thisStep 4. Use this custom field in your CreateOperation and UpdateOperation
Step 5. Result
That's all guys, let me know what you think, also if you get any issues, let me know, thanks 🙏
Beta Was this translation helpful? Give feedback.
All reactions