Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=computer_science_resources
Expand All @@ -48,20 +48,23 @@ REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_SCHEME=null
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="noreply@computerscienceresources.com"
MAIL_FROM_NAME="${APP_NAME}"
MAIL_TO_ADMIN=admin@computerscienceresources.com

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
FILESYSTEM_PUBLIC_DRIVER=local

B2_ACCESS_KEY_ID=
B2_SECRET_ACCESS_KEY=
B2_DEFAULT_REGION=
B2_BUCKET=
B2_ENDPOINT=

VITE_APP_NAME="${APP_NAME}"

Expand Down
12 changes: 11 additions & 1 deletion app/Http/Controllers/ComputerScienceResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,24 @@ public function create()
public function store(StoreResourceRequest $request)
{
$validatedData = $request->validated();
Log::debug('Called store resource with data '.json_encode($request));

DB::beginTransaction();
try {
// Store the image onto storage
$path = null;
if (array_key_exists('image_file', $validatedData) && $imageFile = $validatedData['image_file']) {
$path = $imageFile->store('resource', 'public');
if (! $path) {
Log::error('Failed to store image file', [
'user_id' => Auth::id(),
'file_info' => $imageFile,
]);

$fileName = method_exists($imageFile, 'getClientOriginalName') ? $imageFile->getClientOriginalName() : 'unknown';
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method_exists check for 'getClientOriginalName' is unnecessary complexity. Laravel's UploadedFile class always has this method. Simplify to: $fileName = $imageFile->getClientOriginalName();

Suggested change
$fileName = method_exists($imageFile, 'getClientOriginalName') ? $imageFile->getClientOriginalName() : 'unknown';
$fileName = $imageFile->getClientOriginalName();

Copilot uses AI. Check for mistakes.
throw new \RuntimeException(
"Could not save the image file '{$fileName}' for user ID ".Auth::id().'.'
);
}
}

$resource = ComputerScienceResource::create([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function rules(): array
'topic_tags.*' => ['required', 'distinct', 'string', 'max:50'],

// Optional, can just be omitted
'image_file' => ['nullable', 'image', 'max:400'], // 400 kiloBytes
'image_file' => ['nullable', 'image', 'max:500'], // 500 kiloBytes
'general_tags' => ['array'],
'general_tags.*' => ['required', 'distinct', 'string', 'max:50'],
'programming_language_tags' => ['array'],
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/ResourceEdit/StoreResourceEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function rules(): array
'proposed_changes.pricing' => ['nullable', 'string', Rule::in(config('computerScienceResource.pricings'))],
'proposed_changes.topic_tags' => ['nullable', 'array', 'min:2'],
'proposed_changes.topic_tags.*' => ['required', 'distinct', 'string', 'max:50'],
'proposed_changes.image_file' => ['nullable', 'image', 'max:400'], // 400 kilobytes
'proposed_changes.image_file' => ['nullable', 'image', 'max:500'], // 500 kilobytes
'proposed_changes.general_tags' => ['nullable', 'array'],
'proposed_changes.general_tags.*' => ['required', 'distinct', 'string', 'max:50'],
'proposed_changes.programming_language_tags' => ['nullable', 'array'],
Expand Down
2 changes: 1 addition & 1 deletion app/Models/ComputerScienceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function user(): BelongsTo
protected function imageUrl(): Attribute
{
return Attribute::make(
get: fn () => $this->image_path ? Storage::url($this->image_path) : null,
get: fn () => $this->image_path ? Storage::disk('public')->url($this->image_path) : null,
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/NewsPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NewsPost extends Model
protected function thumbnailUrl(): Attribute
{
return Attribute::make(
get: fn () => Storage::url($this->thumbnail_path)
get: fn () => Storage::disk('public')->url($this->thumbnail_path)
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/ResourceEdits.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function proposedChanges(): Attribute
if (array_key_exists('image_path', $changes)) {
$changes['image_url'] = null;
if ($changes['image_path']) {
$changes['image_url'] = Storage::url($changes['image_path']);
$changes['image_url'] = Storage::disk('public')->url($changes['image_path']);
}
}

Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "MIT",
"require": {
"php": "^8.2",
"aws/aws-sdk-php": "3.336",
"cviebrock/eloquent-sluggable": "^11.0",
"filament/filament": "^3.3",
"filament/tables": "^3.3",
Expand All @@ -17,10 +18,13 @@
"laravel/jetstream": "^5.3",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9",
"league/flysystem-aws-s3-v3": "^3.0",
"shiftonelabs/laravel-cascade-deletes": "^2.0",
"spatie/laravel-activitylog": "^4.10",
"spatie/laravel-backup": "^9.3",
"spatie/laravel-tags": "^4.9",
"tightenco/ziggy": "^2.0"
"tightenco/ziggy": "^2.0",
"yaza/laravel-google-drive-storage": "^4.1"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.14",
Expand Down
Loading