-
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.
* #24 - news draft * #24 - news pagination * #24 - composer update * #24 - gha php bump * #24 - code review changes * #24 - lintf * #24 - lintf * #24 - sanitizeHtml * #24 - csf * #24 - conflicts
- Loading branch information
1 parent
818c257
commit 2f713a2
Showing
22 changed files
with
528 additions
and
185 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
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Observers; | ||
|
||
use App\Models\News; | ||
use Illuminate\Support\Str; | ||
|
||
class NewsObserver | ||
{ | ||
public function creating(News $news): void | ||
{ | ||
if ($news->slug) { | ||
return; | ||
} | ||
|
||
$slug = Str::slug($news->published_at->format("Y-m-d") . " " . $news->title); | ||
|
||
if (!$this->checkIfSlugExists($slug)) { | ||
$news->slug = $slug; | ||
|
||
return; | ||
} | ||
|
||
$i = 2; | ||
|
||
while (true) { | ||
$newSlug = Str::slug($slug . " " . $i); | ||
|
||
if (!$this->checkIfSlugExists($newSlug)) { | ||
$news->slug = $newSlug; | ||
|
||
return; | ||
} | ||
|
||
$i++; | ||
} | ||
} | ||
|
||
protected function checkIfSlugExists(string $slug): bool | ||
{ | ||
return News::query()->where("slug", $slug)->count() > 0; | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
File renamed without changes.
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Seeders; | ||
|
||
use App\Models\News; | ||
use Illuminate\Database\Seeder; | ||
|
||
class DemoSeeder extends Seeder | ||
{ | ||
public function run(): void | ||
{ | ||
News::factory(20)->create(); | ||
} | ||
} |
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
Oops, something went wrong.