initial import
This commit is contained in:
40
app/Console/Commands/FixStyleImagePaths.php
Normal file
40
app/Console/Commands/FixStyleImagePaths.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Style;
|
||||
|
||||
class FixStyleImagePaths extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:fix-style-image-paths';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Prepend style_previews/ to the preview_image path for all styles';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$styles = Style::all();
|
||||
|
||||
foreach ($styles as $style) {
|
||||
if (!str_starts_with($style->preview_image, 'style_previews/')) {
|
||||
$style->preview_image = 'style_previews/' . $style->preview_image;
|
||||
$style->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->info('Image paths for styles have been updated successfully.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user