Skip to content

Commit

Permalink
Update TopicResourceFactory.php (#322)
Browse files Browse the repository at this point in the history
* Update TopicResourceFactory.php

* Update CourseFactory.php

* Update CourseFactory.php

* Update CourseFactory.php
  • Loading branch information
qunabu authored Mar 25, 2024
1 parent 75609cc commit 394619f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
15 changes: 5 additions & 10 deletions database/factories/CourseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use EscolaLms\Courses\Models\Course;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;

class CourseFactory extends Factory
{
Expand Down Expand Up @@ -64,16 +65,10 @@ public function configure()
$filename_image = "course/$id/" . $word . ".jpg";
$filename_video = "course/$id/" . $word . ".mp4";
$filename_poster = "course/$id/" . $word . "poster.jpg";
$dest_image = Storage::disk('public')->path($filename_image);
$dest_video = Storage::disk('public')->path($filename_video);
$dest_poster = Storage::disk('public')->path($filename_poster);
$destDir = dirname($dest_image);
if (!is_dir($destDir)) {
mkdir($destDir, 0777, true);
}
copy(realpath(__DIR__ . "/../mocks/1.jpg"), $dest_image);
copy(realpath(__DIR__ . "/../mocks/1.mp4"), $dest_video);
copy(realpath(__DIR__ . "/../mocks/poster.jpg"), $dest_poster);

Storage::putFileAs("course/{$id}", new File(__DIR__ . '/../mocks/1.jpg'), $filename_image);
Storage::putFileAs("course/{$id}", new File(__DIR__ . '/../mocks/1.mp4'), $filename_video);
Storage::putFileAs("course/{$id}", new File(__DIR__ . '/../mocks/poster.jpg'), $filename_poster);

$course->update([
'image_path' => $filename_image,
Expand Down
7 changes: 3 additions & 4 deletions database/factories/TopicResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use EscolaLms\Courses\Models\TopicResource;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;

class TopicResourceFactory extends Factory
{
Expand Down Expand Up @@ -38,10 +39,8 @@ public function forTopic(Topic $topic)
$path = "course/{$course_id}/topic/{$topic_id}/resources/{$filename}";
$dest = Storage::disk('public')->path($path);
$destDir = dirname($dest);
if (!is_dir($destDir)) {
mkdir($destDir, 0777, true);
}
copy(realpath(__DIR__ . '/../mocks/1.pdf'), $dest);
Storage::putFileAs("course/{$course_id}/topic/{$topic_id}/resources", new File(__DIR__ . '/../mocks/1.pdf'), $filename);

return [
'topic_id' => $topic,
'path' => $path,
Expand Down

0 comments on commit 394619f

Please sign in to comment.