-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into minimal-theme
- Loading branch information
Showing
135 changed files
with
2,685 additions
and
956 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Database\Seeders\LocalImages; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
use Illuminate\Support\Str; | ||
|
||
class GetRandomImages extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:get-random-images'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Get random images stored locally, so that the seed process can be fast.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
// Use an empty string to get random images | ||
// We could fine-tune with search terms, examples: 'nature', 'people', 'city', 'abstract', 'food', 'sports', 'technics', 'transport', 'animals' | ||
// This needs some deeper research to get the best results | ||
|
||
$schemas = [ | ||
['amount' => 40, 'size' => LocalImages::SIZE_200x200, 'terms' => ['']], | ||
['amount' => 40, 'size' => LocalImages::SIZE_1280x720, 'terms' => ['']], | ||
]; | ||
|
||
foreach ($schemas as $schema) { | ||
$this->getRandomImages($schema); | ||
} | ||
|
||
foreach ($schemas as $schema) { | ||
$this->removeDuplicates($schema); | ||
} | ||
} | ||
|
||
protected function getRandomImages($schema) | ||
{ | ||
['amount' => $amount, 'size' => $size, 'terms' => $terms] = $schema; | ||
|
||
$this->comment("Getting $amount random images of size $size, of topic: " . implode(', ', $terms)); | ||
|
||
File::deleteDirectory(database_path('seeders/local_images/' . $size)); | ||
|
||
$progressBar = $this->output->createProgressBar($amount); | ||
$progressBar->start(); | ||
|
||
foreach (range(1, $amount) as $i) { | ||
$url = "https://source.unsplash.com/{$size}/?img=1," . implode(',', $terms); | ||
$image = file_get_contents($url); | ||
|
||
File::ensureDirectoryExists(database_path('seeders/local_images/' . $size)); | ||
$filename = Str::uuid() . '.jpg'; | ||
|
||
File::put( | ||
database_path( | ||
path: "seeders/local_images/{$size}/{$filename}" | ||
), | ||
contents: $image | ||
); | ||
|
||
$progressBar->advance(); | ||
} | ||
|
||
$progressBar->finish(); | ||
|
||
$this->newLine(); | ||
$this->info('Done!'); | ||
} | ||
|
||
protected function removeDuplicates($schema) | ||
{ | ||
['size' => $size] = $schema; | ||
|
||
$allFiles = fn () => collect(File::files(database_path('seeders/local_images/' . $size))); | ||
|
||
$uniqueImageSet = $allFiles() | ||
->mapWithKeys(fn ($file) => [md5_file($file->getPathname()) => $file->getPathname()]) | ||
->values(); | ||
|
||
$allFiles() | ||
->map(fn ($file) => $file->getPathname()) | ||
->diff($uniqueImageSet) | ||
->each(fn ($file) => File::delete($file)); | ||
|
||
$this->info('Kept ' . $uniqueImageSet->count() . " unique files from size $size"); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace App\Filament\Clusters; | ||
|
||
use Filament\Clusters\Cluster; | ||
|
||
class Products extends Cluster | ||
{ | ||
protected static ?string $navigationIcon = 'heroicon-o-squares-2x2'; | ||
|
||
protected static ?string $navigationGroup = 'Shop'; | ||
|
||
protected static ?int $navigationSort = 0; | ||
|
||
protected static ?string $slug = 'shop/products'; | ||
} |
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
4 changes: 2 additions & 2 deletions
4
.../Shop/BrandResource/Pages/CreateBrand.php → ...urces/BrandResource/Pages/CreateBrand.php
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
4 changes: 2 additions & 2 deletions
4
...es/Shop/BrandResource/Pages/EditBrand.php → ...sources/BrandResource/Pages/EditBrand.php
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
4 changes: 2 additions & 2 deletions
4
...ationManagers/ProductsRelationManager.php → ...ationManagers/ProductsRelationManager.php
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
4 changes: 2 additions & 2 deletions
4
...CategoryResource/Pages/CreateCategory.php → ...CategoryResource/Pages/CreateCategory.php
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
4 changes: 2 additions & 2 deletions
4
...p/CategoryResource/Pages/EditCategory.php → ...s/CategoryResource/Pages/EditCategory.php
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
4 changes: 2 additions & 2 deletions
4
...CategoryResource/Pages/ListCategories.php → ...CategoryResource/Pages/ListCategories.php
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
4 changes: 2 additions & 2 deletions
4
...ationManagers/ProductsRelationManager.php → ...ationManagers/ProductsRelationManager.php
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.