diff --git a/app/Console/Commands/example_code_to_markdown.php b/app/Console/Commands/example_code_to_markdown.php index 042fe42..312695d 100644 --- a/app/Console/Commands/example_code_to_markdown.php +++ b/app/Console/Commands/example_code_to_markdown.php @@ -24,7 +24,7 @@ class example_code_to_markdown extends Command /** * Execute the console command. */ - public function handle() + public function handle(): void { foreach (Item::all() as $item) { $item->example_code = $this->convertCodeToMarkdown($item->example_code); @@ -35,7 +35,7 @@ public function handle() private function convertCodeToMarkdown(string $code): string { return '``` -' . $code . ' +'.$code.' ```'; } } diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php index 9fc792c..7a6ebab 100644 --- a/app/Http/Controllers/PhotoController.php +++ b/app/Http/Controllers/PhotoController.php @@ -14,7 +14,7 @@ public function store(Request $request, int $itemId) $item = Item::findOrFail($itemId); $photo = $request->file('photo'); - if(!$photo) { + if (! $photo) { return response()->json(['error' => 'No photo provided'], 400); } @@ -25,7 +25,7 @@ public function store(Request $request, int $itemId) 'path' => $photo->hashName(), ]); - return ['url'=>$photoModel->url, 'id'=>$photoModel->id]; + return ['url' => $photoModel->url, 'id' => $photoModel->id]; } public function destroy(Request $request, int $itemId, int $photoId) @@ -33,7 +33,7 @@ public function destroy(Request $request, int $itemId, int $photoId) $item = Item::findOrFail($itemId); $photo = Photo::findOrFail($photoId); - if($photo->item_id !== $item->id) { + if ($photo->item_id !== $item->id) { return response()->json(['error' => 'Photo does not belong to item'], 400); } diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 16d867e..7ff128a 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -19,12 +19,13 @@ public function item(): BelongsTo { return $this->belongsTo(Item::class); } + public function getUrlAttribute(): string { return asset('storage/photos/'.$this->path); } - public static function boot(): void + protected static function boot(): void { parent::boot(); static::deleting(static function (Photo $photo): void {