princeoo7
3 months ago
681
5
Laravel

Create fake pdf or image in laravel seeder at the time of migration and store the record in database

Posted 3 months ago by princeoo7

Below is what I have in by UserTableSeeder file

        $docRange = mt_rand(1,10);

                foreach(range(1, $docRange) as $d) {
                    $dname = strtotime(date("Y-m-d H:i:s")).'.pdf';
                    $document = UploadedFile::fake()->create($dname);
                    Storage::fake('documents');
                    Storage::disk('documents')->assertExists($document);
                    Log::Debug($document);
               }

Now the issue is I get the following error:

PHPUnit\Framework\ExpectationFailedException  : Unable to find a file at path [/private/var/folders/00/7td5x8fx0j3ftjy5v_yppt0c0000gn/T/phpqN2Ew1].
Failed asserting that false is true.

I am not trying to create a unit test, but dummy data for testing on the live app.

if I remove Storage::disk('documents')->assertExists($document); line the seeder successfully execute but then I don't get the file in storage folder. I do get a folder called documents in testing folder but that is not what I want.

what is the way I should go?

Please sign in or create an account to participate in this conversation.