This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
generated from LexianDEV/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update MOTD package: improve package description and update configura…
…tion
- Loading branch information
1 parent
08d03fd
commit d0d54a4
Showing
6 changed files
with
72 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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 GitHub Actions / phpstan
|
||
->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; | ||
} 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 GitHub Actions / phpstan
Check failure on line 42 in src/Models/motd.php GitHub Actions / phpstan
|
||
'message' => $message, | ||
'start_date' => $start_date, | ||
'end_date' => $end_date, | ||
]); | ||
|
||
return true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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