Skip to content

Commit

Permalink
Merge pull request #40 from RonasIT/39-move-max-upload-size-to-config
Browse files Browse the repository at this point in the history
#39 Move max upload size to config
  • Loading branch information
DenTray authored Dec 13, 2024
2 parents ba68d5a + 1f8b492 commit 1d556d2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
30 changes: 30 additions & 0 deletions config/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,47 @@
use App\Models\User;

return [
/*
|--------------------------------------------------------------------------
| Permitted file types
|--------------------------------------------------------------------------
|
| The list of permitted file types
*/
'permitted_types' => [
'jpg',
'jpeg',
'bmp',
'png',
],

/*
|--------------------------------------------------------------------------
| Max File Size
|--------------------------------------------------------------------------
|
| Max file size in kilobytes
*/
'max_file_size' => 5120,

'classes' => [
/*
|--------------------------------------------------------------------------
| User model
|--------------------------------------------------------------------------
|
| Authenticatable User model which will be used to create owner relation with Media
*/
'user_model' => User::class,
],

/*
|--------------------------------------------------------------------------
| Preview
|--------------------------------------------------------------------------
|
| File preview width and height in pixels which will be used to create preview
*/
'preview' => [
'width' => 250,
'height' => 250,
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Requests/BulkCreateMediaRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ class BulkCreateMediaRequest extends BaseRequest implements BulkCreateMediaReque
public function rules(): array
{
$types = implode(',', config('media.permitted_types'));
$maxFileSize = config('media.max_file_size');

return [
'media' => 'required|array',
'media.*' => 'array',
'media.*.file' => "file|required|max:5120|mimes:{$types}",
'media.*.file' => "file|required|max:{$maxFileSize}|mimes:{$types}",
'media.*.meta' => 'array',
'media.*.is_public' => 'boolean',
];
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Requests/CreateMediaRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class CreateMediaRequest extends BaseRequest implements CreateMediaRequestContra
public function rules(): array
{
$types = implode(',', config('media.permitted_types'));
$maxFileSize = config('media.max_file_size');

return [
'file' => "file|required|max:5120|mimes:{$types}",
'file' => "file|required|max:{$maxFileSize}|mimes:{$types}",
'meta' => 'array',
'is_public' => 'boolean',
];
Expand Down

0 comments on commit 1d556d2

Please sign in to comment.