From 5367b4bb853d3436a90987524ad53828902710dc Mon Sep 17 00:00:00 2001 From: WebVPF <61043464+WebVPF@users.noreply.github.com> Date: Mon, 4 Nov 2024 08:16:21 +0200 Subject: [PATCH] Fix code style (#219) --- database/attachments.md | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/database/attachments.md b/database/attachments.md index f9388e4b..6eeb4883 100644 --- a/database/attachments.md +++ b/database/attachments.md @@ -16,7 +16,7 @@ A single file attachment: ```php public $attachOne = [ - 'avatar' => 'System\Models\File' + 'avatar' => \System\Models\File::class, ]; ``` @@ -24,7 +24,7 @@ Multiple file attachments: ```php public $attachMany = [ - 'photos' => 'System\Models\File' + 'photos' => \System\Models\File::class, ]; ``` @@ -34,7 +34,10 @@ Protected attachments are uploaded to the File Upload disk's **uploads/protected ```php public $attachOne = [ - 'avatar' => ['System\Models\File', 'public' => false] + 'avatar' => [ + \System\Models\File::class, + 'public' => false, + ], ]; ``` @@ -137,14 +140,14 @@ Inside your model define a relationship to the `System\Models\File` class, for e class Post extends Model { public $attachOne = [ - 'featured_image' => 'System\Models\File' + 'featured_image' => \System\Models\File::class, ]; } ``` Build a form for uploading a file: -```html +```php true]) ?> @@ -184,16 +187,18 @@ if ($fileFromPost) { Display the uploaded file on a page: ```php -// Find the Blog Post model again -$post = Post::find(1); +featured_image) { - $featuredImage = $post->featured_image->getPath(); -} -else { - $featuredImage = 'http://placehold.it/220x300'; -} + // Look for the featured image address, otherwise use a default one + if ($post->featured_image) { + $featuredImage = $post->featured_image->getPath(); + } + else { + $featuredImage = 'http://placehold.it/220x300'; + } +?> Featured Image ```