Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Update MOTD package: improve package description and update configura…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Lexian-droid committed Mar 10, 2024
1 parent 08d03fd commit d0d54a4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 29 deletions.
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/lexiandev/laravel-motd/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/lexiandev/laravel-motd/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/lexiandev/laravel-motd.svg?style=flat-square)](https://packagist.org/packages/lexiandev/laravel-motd)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
This is a simple package to display MOTD messages to your users, it can
be used to display updates, maintenance messages, or any other message
you want to display to your users.

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-motd.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-motd)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
When using the package, simply call the `get` method on the motd model
and it'll return the **newest** message that is not expired.

## Installation

Expand All @@ -26,34 +23,33 @@ composer require lexiandev/laravel-motd
You can publish and run the migrations with:

```bash
php artisan vendor:publish --tag="laravel-motd-migrations"
php artisan vendor:publish --tag="motd-migrations"
php artisan migrate
```

You can publish the config file with:

```bash
php artisan vendor:publish --tag="laravel-motd-config"
php artisan vendor:publish --tag="motd-config"
```

This is the contents of the published config file:

```php
return [
/**
* The default text that will be displayed if no MOTD is set.
* Default: Null; no message will be returned.
*/
'default_message' => null,
];
```

Optionally, you can publish the views using

```bash
php artisan vendor:publish --tag="laravel-motd-views"
```

## Usage

```php
$motd = new Lexiandev\Motd();
echo $motd->echoPhrase('Hello, Lexiandev!');
$motd = new Motd();
return $motd->get();
```

## Testing
Expand All @@ -67,7 +63,7 @@ composer test
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security Vulnerabilities
Expand Down
6 changes: 5 additions & 1 deletion config/motd.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

// config for Lexiandev/Motd
return [

/**
* The default text that will be displayed if no MOTD is set.
* Default: Null; no message will be returned.
*/
'default_message' => null,
];
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ return new class extends Migration
{
public function up()
{
Schema::create('laravel_motd_table', function (Blueprint $table) {
Schema::create('motds', function (Blueprint $table) {
$table->id();

$table->string('message');
Expand Down
50 changes: 50 additions & 0 deletions src/Models/motd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Lexiandev\Motd\Models;

use Illuminate\Database\Eloquent\Model;

class Motd extends Model
{
protected $table = 'motds';

protected $fillable = [
'message',
'start_date',
'end_date',
];

protected $dates = [
'start_date',
'end_date',
];

public function get()
{
$query = $this->where('start_date', '<=', now())

Check failure on line 24 in src/Models/motd.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'end_date' does not exist in Lexiandev\Motd\Models\Motd model.

Check failure on line 24 in src/Models/motd.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'start_date' does not exist in Lexiandev\Motd\Models\Motd model.
->where('end_date', '>=', now())
->orderBy('created_at', 'desc') // Order by created_at in descending order
->first(); // Retrieve only the newest message

if ($query) {
return $query->message;

Check failure on line 30 in src/Models/motd.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Lexiandev\Motd\Models\Motd::$message.
} else {
return config('motd.default_message');
}
}

public function set($message, $start_date, $end_date)
{
// Convert unix timestamps to Carbon instances
$start_date = \Carbon\Carbon::createFromTimestamp($start_date);
$end_date = \Carbon\Carbon::createFromTimestamp($end_date);

$this->create([

Check failure on line 42 in src/Models/motd.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'end_date' does not exist in Lexiandev\Motd\Models\Motd model.

Check failure on line 42 in src/Models/motd.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'message' does not exist in Lexiandev\Motd\Models\Motd model.

Check failure on line 42 in src/Models/motd.php

View workflow job for this annotation

GitHub Actions / phpstan

Property 'start_date' does not exist in Lexiandev\Motd\Models\Motd model.
'message' => $message,
'start_date' => $start_date,
'end_date' => $end_date,
]);

return true;
}
}
7 changes: 0 additions & 7 deletions src/Motd.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/MotdServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function configurePackage(Package $package): void
->name('laravel-motd')
->hasConfigFile()
->hasViews()
->hasMigration('create_laravel-motd_table')
->hasMigration('create_motds_table')
->hasCommand(MotdCommand::class);
}
}

0 comments on commit d0d54a4

Please sign in to comment.