feat(broadcast): menambahkan kolom baru yaitu link dan menyesuaikan logikanya
This commit is contained in:
parent
b7c32d2ffb
commit
22af59f641
@ -37,6 +37,8 @@ public function columns(): array
|
|||||||
</div>', ['value' => $value]))
|
</div>', ['value' => $value]))
|
||||||
->flexRow(['class' => 'gap-2 flex-wrap']),
|
->flexRow(['class' => 'gap-2 flex-wrap']),
|
||||||
|
|
||||||
|
Column::make('Tautan', 'link')->searchable(),
|
||||||
|
|
||||||
Column::make('Aksi')
|
Column::make('Aksi')
|
||||||
->label(function ($row) {
|
->label(function ($row) {
|
||||||
return view('components.actions.table.delete', [
|
return view('components.actions.table.delete', [
|
||||||
|
|||||||
@ -18,6 +18,8 @@ class BroadcastForm extends Form
|
|||||||
|
|
||||||
public string $body = '';
|
public string $body = '';
|
||||||
|
|
||||||
|
public ?string $link = null;
|
||||||
|
|
||||||
public array $role_ids = [];
|
public array $role_ids = [];
|
||||||
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
@ -25,6 +27,7 @@ public function rules(): array
|
|||||||
return [
|
return [
|
||||||
'title' => ['required', 'string', 'max:30'],
|
'title' => ['required', 'string', 'max:30'],
|
||||||
'body' => ['required', 'string', 'max:50'],
|
'body' => ['required', 'string', 'max:50'],
|
||||||
|
'link' => ['nullable', 'url', 'max:50'],
|
||||||
'role_ids' => ['required', 'array', 'min:1'],
|
'role_ids' => ['required', 'array', 'min:1'],
|
||||||
'role_ids.*' => Rule::exists('roles', 'id'),
|
'role_ids.*' => Rule::exists('roles', 'id'),
|
||||||
];
|
];
|
||||||
@ -34,6 +37,7 @@ public function validationAttributes(): array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'title' => 'judul',
|
'title' => 'judul',
|
||||||
|
'link' => 'tautan',
|
||||||
'role_ids' => 'audiensi',
|
'role_ids' => 'audiensi',
|
||||||
'role_ids.*' => 'audiensi',
|
'role_ids.*' => 'audiensi',
|
||||||
];
|
];
|
||||||
@ -45,6 +49,7 @@ public function setBroadcast(Broadcast $broadcast): void
|
|||||||
|
|
||||||
$this->title = $broadcast->title;
|
$this->title = $broadcast->title;
|
||||||
$this->body = $broadcast->body;
|
$this->body = $broadcast->body;
|
||||||
|
$this->link = $broadcast->link;
|
||||||
$this->role_ids = $broadcast->audiences->pluck('id')->toArray();
|
$this->role_ids = $broadcast->audiences->pluck('id')->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +62,7 @@ public function store(): array
|
|||||||
'user_id' => auth()->id(),
|
'user_id' => auth()->id(),
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'body' => $this->body,
|
'body' => $this->body,
|
||||||
|
'link' => $this->link,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$broadcast->audiences()->attach($this->role_ids);
|
$broadcast->audiences()->attach($this->role_ids);
|
||||||
@ -65,20 +71,8 @@ public function store(): array
|
|||||||
return [
|
return [
|
||||||
'title' => $broadcast->title,
|
'title' => $broadcast->title,
|
||||||
'body' => $broadcast->body,
|
'body' => $broadcast->body,
|
||||||
|
'link' => $broadcast->link,
|
||||||
'audience_ids' => $this->role_ids,
|
'audience_ids' => $this->role_ids,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(): void
|
|
||||||
{
|
|
||||||
$this->validate();
|
|
||||||
|
|
||||||
DB::transaction(function () {
|
|
||||||
$this->broadcast->update([
|
|
||||||
'title' => $this->title,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->broadcast->audiences()->sync($this->role_ids);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,6 +60,7 @@ public function create(): void
|
|||||||
[
|
[
|
||||||
'title' => $result['title'],
|
'title' => $result['title'],
|
||||||
'body' => $result['body'],
|
'body' => $result['body'],
|
||||||
|
'url' => $result['link'],
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ public function up(): void
|
|||||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||||
$table->string('title', 30);
|
$table->string('title', 30);
|
||||||
$table->string('body', 50);
|
$table->string('body', 50);
|
||||||
|
$table->string('link', 50)->nullable();
|
||||||
$table->timestamp('created_at')->useCurrent();
|
$table->timestamp('created_at')->useCurrent();
|
||||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -45,6 +45,10 @@
|
|||||||
<flux:error name="form.body" />
|
<flux:error name="form.body" />
|
||||||
</flux:field>
|
</flux:field>
|
||||||
|
|
||||||
|
<flux:input label="Tautan"
|
||||||
|
placeholder="https://yadiparfum.com/articles"
|
||||||
|
wire:model="form.link" autocomplete="off" />
|
||||||
|
|
||||||
<flux:field>
|
<flux:field>
|
||||||
<flux:label>Audiensi <span class="text-red-500 ms-1">*</span></flux:label>
|
<flux:label>Audiensi <span class="text-red-500 ms-1">*</span></flux:label>
|
||||||
<flux:select variant="listbox" multiple searchable placeholder="Pilih Audiensi"
|
<flux:select variant="listbox" multiple searchable placeholder="Pilih Audiensi"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user