You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Desperately needed a formfield type that would be helpful in creating tags and I know there could be the approach of storing a string and exploding via separation through commas but that's not neat at all and a bit complex as well. So I made a custom formfield that accepts tags at the time of input and stores it as an array. It works similary to the Multiple Dropdown formfield but instead of having to declare options beforehand and only being able to choose from those, this approach lets you create them dynamically. Its not the cleanest looking but it works. I hope voyager makes a default tags formfield in near future.
Proposed solution
Steps to reproduce:
Make a folder named "FormFields" inside Laravel's "App" folder so the directory looks like this "App/FormFields"
Inside FormFields folder create a php file named "TagsFormField.php" and use this code
<?php
namespace App\FormFields;
use TCG\Voyager\FormFields\AbstractHandler;
class TagsFormField extends AbstractHandler
{
protected $codename = 'tags';
public function createContent($row, $dataType, $dataTypeContent, $options)
{
return view('voyager::formfields.tags', [
'row' => $row,
'dataType' => $dataType,
'dataTypeContent' => $dataTypeContent,
'options' => $options,
]);
}
}
Now go to "vendor\tcg\voyager\resources\views\formfields" and create a blade file named "tags.blade.php". Paste this code there
Now the last step is to go to "App/Providers/AppServiceProvider.php" and paste this code
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\FormFields\TagsFormField;
use TCG\Voyager\Facades\Voyager;
use Illuminate\Support\Facades\View;
use App\Http\ViewComposers\CartComposer;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot()
{
Voyager::addFormField(TagsFormField::class);
View::composer('*', CartComposer::class);
}
}
Alternatives considered
No response
Additional context
Screenshots attached
The text was updated successfully, but these errors were encountered:
Laravel version
10.0
PHP version
8.1
Voyager version
1.6
Description of problem
Desperately needed a formfield type that would be helpful in creating tags and I know there could be the approach of storing a string and exploding via separation through commas but that's not neat at all and a bit complex as well. So I made a custom formfield that accepts tags at the time of input and stores it as an array. It works similary to the Multiple Dropdown formfield but instead of having to declare options beforehand and only being able to choose from those, this approach lets you create them dynamically. Its not the cleanest looking but it works. I hope voyager makes a default tags formfield in near future.
Proposed solution
Steps to reproduce:
Alternatives considered
No response
Additional context
Screenshots attached
The text was updated successfully, but these errors were encountered: