Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up(): void
{
Schema::table('announcements', function (Blueprint $table) {
$table->boolean('all_users')
->default(false)
->after('users');
});
}

public function down(): void
{
Schema::table('announcements', function (Blueprint $table) {
//
Copy link
Owner

@rupadana rupadana Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rizayev please drop all_users column in this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be checked ASAP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rupadana is it okay?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it okay now?

Copy link
Owner

@rupadana rupadana Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to letting this request still opened

i think this problem already fixed on this PR #22

Let me know if you still see this issue

});
}
};
1 change: 1 addition & 0 deletions src/Models/Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Announcement extends Model
'body',
'icon',
'users',
'all_users'
];

protected $casts = [
Expand Down
63 changes: 36 additions & 27 deletions src/Resources/AnnouncementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use App\Models\User;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
Expand All @@ -29,34 +32,40 @@ public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->minLength(5)
->required(),
TextInput::make('title')
->minLength(5)
->required(),
Textarea::make('body')
->minLength(20)
->required(),
IconPicker::make('icon'),
Select::make('color')
->options([
...collect(FilamentColor::getColors())->map(fn ($value, $key) => ucfirst($key))->toArray(),
'custom' => 'Custom',
])
->live(),
ColorPicker::make('custom_color')
->hidden(fn (Get $get) => $get('color') != 'custom')
->requiredIf('color', 'custom')
->rgb(),
Section::make()
->schema([
TextInput::make('name')
->minLength(5)
->required(),
TextInput::make('title')
->minLength(5)
->required(),
Textarea::make('body')
->minLength(20)
->required(),
IconPicker::make('icon'),
Select::make('color')
->options([
...collect(FilamentColor::getColors())->map(fn($value, $key) => ucfirst($key))->toArray(),
'custom' => 'Custom',
])
->live(),
ColorPicker::make('custom_color')
->hidden(fn(Get $get) => $get('color') != 'custom')
->requiredIf('color', 'custom')
->rgb(),

Select::make('users')
->options([
'all' => 'all',
...User::all()->pluck('name', 'id'),
])
->multiple()
->required(),
Select::make('users')
->options(User::pluck('name', 'id')->toArray())
->hidden(fn(Get $get) => $get('all_users'))
->multiple()
->required(),
])->columns(2),

Toggle::make('all_users')
->live()
->label('All users')
->default(false),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public function afterCreate()
$icon = $record->icon;
$title = $record->title;
$body = $record->body;

$isNotifyToAll = in_array('all', $record->users);

$users = $isNotifyToAll ? User::all() : User::query()->whereIn('id', $record->users)->get();
$isForAll = $record->all_users;

$users = $isForAll ? User::all() : User::query()->whereIn('id', $record->users)->get();

$announce = Announce::make();

Expand Down