Last active
February 22, 2026 14:38
-
-
Save jaysavage83/356c939b3cea0239371f3d30fb6aff9f to your computer and use it in GitHub Desktop.
Laravel alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| app/events/SiteAnnouncement.php | |
| */ | |
| namespace App\Events; | |
| use App\Models\Announcement; | |
| use Illuminate\Broadcasting\Channel; | |
| use Illuminate\Broadcasting\InteractsWithSockets; | |
| use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | |
| use Illuminate\Foundation\Events\Dispatchable; | |
| use Illuminate\Queue\SerializesModels; | |
| class SiteAnnouncement implements ShouldBroadcast | |
| { | |
| use Dispatchable, InteractsWithSockets, SerializesModels; | |
| public $message; | |
| public function __construct($message) { | |
| $this->message = $message; | |
| } | |
| public function broadcastOn(): Channel { | |
| return new Channel('public.announcements'); // Public channel | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| app/Filament/Resources/AnnouncementResource.php | |
| */ | |
| namespace App\Filament\Resources; | |
| use App\Filament\Resources\AnnouncementResource\Pages; | |
| use App\Filament\Resources\AnnouncementResource\RelationManagers; | |
| use App\Models\Announcement; | |
| use Filament\Forms; | |
| use Filament\Forms\Form; | |
| use Filament\Forms\Components\TextInput; | |
| use Filament\Forms\Components\Textarea; | |
| use Filament\Forms\Components\Toggle; | |
| use Filament\Resources\Resource; | |
| use Filament\Tables; | |
| use Filament\Tables\Table; | |
| use Illuminate\Database\Eloquent\Builder; | |
| use Illuminate\Database\Eloquent\SoftDeletingScope; | |
| class AnnouncementResource extends Resource | |
| { | |
| protected static ?string $model = Announcement::class; | |
| protected static ?string $navigationGroup = 'Notifications'; | |
| protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; | |
| public static function form(Form $form): Form | |
| { | |
| return $form | |
| ->schema([ | |
| Toggle::make('active') | |
| ->columnSpanFull(), | |
| TextInput::make('title') | |
| ->maxLength(255), | |
| TextInput::make('url'), | |
| TextArea::make('text') | |
| ->columnSpanFull(), | |
| ]); | |
| } | |
| public static function table(Table $table): Table | |
| { | |
| return $table | |
| ->columns([ | |
| Tables\Columns\TextColumn::make('title') | |
| ->searchable(), | |
| Tables\Columns\TextColumn::make('text') | |
| ->searchable(), | |
| Tables\Columns\TextColumn::make('url') | |
| ->searchable(), | |
| Tables\Columns\IconColumn::make('active') | |
| ->boolean(), | |
| Tables\Columns\TextColumn::make('created_at') | |
| ->dateTime() | |
| ->sortable() | |
| ->toggleable(isToggledHiddenByDefault: true), | |
| Tables\Columns\TextColumn::make('updated_at') | |
| ->dateTime() | |
| ->sortable() | |
| ->toggleable(isToggledHiddenByDefault: true), | |
| ]) | |
| ->filters([ | |
| // | |
| ]) | |
| ->actions([ | |
| Tables\Actions\EditAction::make(), | |
| ]) | |
| ->bulkActions([ | |
| Tables\Actions\BulkActionGroup::make([ | |
| Tables\Actions\DeleteBulkAction::make(), | |
| ]), | |
| ]); | |
| } | |
| public static function getRelations(): array | |
| { | |
| return [ | |
| // | |
| ]; | |
| } | |
| public static function getPages(): array | |
| { | |
| return [ | |
| 'index' => Pages\ListAnnouncements::route('/'), | |
| 'create' => Pages\CreateAnnouncement::route('/create'), | |
| 'edit' => Pages\EditAnnouncement::route('/{record}/edit'), | |
| ]; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| app/livewire/Announcement.php | |
| */ | |
| namespace App\Livewire; | |
| use Livewire\Component; | |
| class Announcement extends Component | |
| { | |
| public function render() | |
| { | |
| return view('livewire.announcement'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| app/Providers/AppServiceProvider.php | |
| */ | |
| namespace App\Providers; | |
| use Illuminate\Support\ServiceProvider; | |
| use Illuminate\Support\Facades\Gate; | |
| use Illuminate\Contracts\Auth\Access\Gate as GateContract; | |
| use Illuminate\Support\Facades\View; | |
| use App\Models\Announcement; | |
| use CmsMulti\FilamentClearCache\Facades\FilamentClearCache; | |
| class AppServiceProvider extends ServiceProvider | |
| { | |
| /** | |
| * Register any application services. | |
| */ | |
| public function register(): void | |
| { | |
| // | |
| } | |
| /** | |
| * Bootstrap any application services. | |
| */ | |
| public function boot(GateContract $gate) | |
| { | |
| FilamentClearCache::addCommand('page-cache:clear'); | |
| $activeAnnouncement = Announcement::where('active', true)->first(); | |
| // Share the announcement with all views | |
| View::share('activeAnnouncement', $activeAnnouncement); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| app/models/Announcement.php | |
| */ | |
| namespace App\Models; | |
| use Illuminate\Database\Eloquent\Model; | |
| class Announcement extends Model | |
| { | |
| protected $fillable = [ | |
| 'title', 'text', 'url', 'active', | |
| ]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| resources/views/livewire/announcement.blade.php | |
| --> | |
| <!-- livewire --> | |
| <div wire:poll.5s> | |
| @if (isset($activeAnnouncement) && $activeAnnouncement) | |
| <div class="w-full bg-red-700 text-white p-3 text-center font-bold text-lg animate-pulse"> | |
| @if($activeAnnouncement->url) | |
| <a href="{{ $activeAnnouncement->url }}"> | |
| @endif | |
| @if($activeAnnouncement->text) | |
| {{ $activeAnnouncement->text }} | |
| @endif | |
| @if($activeAnnouncement->url) | |
| </a> | |
| @endif | |
| </div> | |
| @endif | |
| </div> | |
| <!-- end --> |
Comments are disabled for this gist.