File manager - Edit - /var/www/html/gop/api/database/factories/ArquivoFactory.php
Back
<?php namespace Database\Factories; use App\Models\Empenho; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\File; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Arquivo> */ class ArquivoFactory extends Factory { /** * Define the model's default state. * * @return array<string, mixed> */ public function definition() { $empenho = Empenho::factory()->create(); $name = fake()->uuid.'.pdf'; $class = Empenho::class; $modelName = str(str_replace('App\Models\\', '', $class)) ->slug(); $path = "arquivos/{$modelName}/".$name; $storagePath = str_replace('\\', '/', storage_path('app/public/'.$path)); $path = str_replace('\\', '/', $path); $filePath = str($storagePath)->replace('/'.$name, ''); if (! File::exists($filePath)) { File::makeDirectory($filePath, 0777, true, true); } File::copy(storage_path('test/pdf-test.pdf'), $storagePath); return [ 'name' => $name, 'path' => $path, 'arquivable_id' => $empenho->id, 'arquivable_type' => Empenho::class, ]; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings