get item relations
This commit is contained in:
@ -3,7 +3,9 @@
|
||||
namespace app\modules\tag;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use itguild\forms\builders\SelectBuilder;
|
||||
use itguild\forms\builders\TextInputBuilder;
|
||||
use itguild\forms\inputs\Select;
|
||||
use kernel\app_modules\tag\models\Tag;
|
||||
use kernel\app_modules\tag\models\TagEntity;
|
||||
use kernel\helpers\Debug;
|
||||
@ -19,6 +21,7 @@ class TagModule extends Module
|
||||
|
||||
public MenuService $menuService;
|
||||
public MigrationService $migrationService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
@ -58,10 +61,12 @@ class TagModule extends Module
|
||||
|
||||
public function formInputs(string $entity, Model $model = null): void
|
||||
{
|
||||
$input = TextInputBuilder::build("tag", [
|
||||
$input = SelectBuilder::build("tag[]", [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Теги',
|
||||
'value' => Tag::find($model->id)->label ?? ""
|
||||
'value' => '',
|
||||
'multiple' => "multiple",
|
||||
'options' => Tag::getTagLabelByEntity($entity)
|
||||
]);
|
||||
$input->setLabel("Теги");
|
||||
$input->create()->render();
|
||||
@ -69,23 +74,21 @@ class TagModule extends Module
|
||||
|
||||
public function saveInputs(string $entity, Model $model, Request $request): void
|
||||
{
|
||||
$tag = new Tag();
|
||||
$tag->label = $request->post('tag');
|
||||
$tag->entity = $entity;
|
||||
$tag->status = Tag::ACTIVE_STATUS;
|
||||
$tag->slug = Slug::createSlug($request->post('tag'), $model);
|
||||
$tag->save();
|
||||
TagEntity::where("entity", $entity)->where("entity_id", $model->id)->delete();
|
||||
|
||||
$tagEntity = new TagEntity();
|
||||
$tagEntity->entity = $entity;
|
||||
$tagEntity->entity_id = $model->id;
|
||||
$tagEntity->tag_id = $tag->id;
|
||||
$tagEntity->save();
|
||||
$tags = $request->post("tag");
|
||||
foreach ($tags as $tag) {
|
||||
$tagEntity = new TagEntity();
|
||||
$tagEntity->entity = $entity;
|
||||
$tagEntity->entity_id = $model->id;
|
||||
$tagEntity->tag_id = $tag;
|
||||
$tagEntity->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function getInputs(string $entity, Model $model)
|
||||
{
|
||||
|
||||
// Debug::dd($tag);
|
||||
public function getItems(string $entity, Model $model): array
|
||||
{
|
||||
return TagEntity::where("entity", $entity)->where("entity_id", $model->id)->with("tag")->get()->toArray();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user