Implement Endpoint sector info file download.
This commit is contained in:
parent
6db02f37b4
commit
ae9e2c9658
@ -3,7 +3,9 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\UploadInfoSectorialRequest;
|
use App\Http\Requests\UploadInfoSectorialRequest;
|
||||||
|
use App\Models\InfoSectorial;
|
||||||
use App\Traits\ApiResponse;
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class InfoSectorialController extends Controller
|
class InfoSectorialController extends Controller
|
||||||
@ -14,31 +16,37 @@ class InfoSectorialController extends Controller
|
|||||||
{
|
{
|
||||||
$data = $uploadInfoSectorialRequest->all();
|
$data = $uploadInfoSectorialRequest->all();
|
||||||
|
|
||||||
if (!$uploadInfoSectorialRequest->hasFile('reportfile')) {
|
if (!$uploadInfoSectorialRequest->hasFile('file')) {
|
||||||
return $this->errorResponse( false, '', 500);
|
return $this->errorResponse( false, '', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $uploadInfoSectorialRequest->file('reportfile');
|
$file = $uploadInfoSectorialRequest->file('file');
|
||||||
|
|
||||||
$data['name'] = Str::of($file->getClientOriginalName())->explode('.')->offsetGet(0);
|
$data['name'] = Str::of($file->getClientOriginalName())->explode('.')->offsetGet(0);
|
||||||
|
$data['uid'] = Str::of($file->hashName())->explode('.')->offsetGet(0);
|
||||||
$extension = $file->getClientOriginalExtension();
|
$extension = $file->getClientOriginalExtension();
|
||||||
|
$data['path'] = $file->storeAs("pdf", $data['uid'].".{$extension}");
|
||||||
|
|
||||||
$data['reportfile'] = $file->storeAs('file', $data['name'].".{$extension}");
|
return InfoSectorial::query()->create($data);
|
||||||
|
|
||||||
dd($data);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function download()
|
public function download()
|
||||||
{
|
{
|
||||||
$file = public_path("Clockify_Time_Report_Detailed_01_05_2022-31_05_2022.pdf");
|
$created_at = InfoSectorial::query()->max('created_at');
|
||||||
|
|
||||||
$path = storage_path("public/file/Clockify_Time_Report_Detailed_01_05_2022-31_05_2022.pdf");
|
$data = InfoSectorial::query()->where('created_at', '=', $created_at)->first();
|
||||||
|
|
||||||
|
if (Storage::disk('public')->exists($data->path))
|
||||||
|
{
|
||||||
|
$path = Storage::disk('public')->path(($data->path));
|
||||||
|
|
||||||
$headers = ['Content-Type: application/pdf'];
|
$heders = [
|
||||||
$newName = 'itsolutionstuff-pdf-file-'.time().'.pdf';
|
'Content-Type' => mime_content_type($path)
|
||||||
|
];
|
||||||
|
|
||||||
|
return response()->download($path, $data->name, $heders);
|
||||||
|
|
||||||
return response()->download($file, $newName, $headers);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class UploadInfoSectorialRequest extends FormRequest
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'reportfile' => 'required|mimes:pdf',
|
'file' => ['required','mimes:pdf'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
app/Models/InfoSectorial.php
Normal file
36
app/Models/InfoSectorial.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class InfoSectorial extends Model
|
||||||
|
{
|
||||||
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
|
protected $table = "info_sectorial";
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'uid',
|
||||||
|
'name',
|
||||||
|
'path',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'updated_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function serializeDate(DateTimeInterface $date): string
|
||||||
|
{
|
||||||
|
return $date->format('d/m/Y H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,7 +11,8 @@
|
|||||||
"laravel/sanctum": "^2.14.1",
|
"laravel/sanctum": "^2.14.1",
|
||||||
"laravel/tinker": "^2.7",
|
"laravel/tinker": "^2.7",
|
||||||
"owen-it/laravel-auditing": "^13.0",
|
"owen-it/laravel-auditing": "^13.0",
|
||||||
"umbrellio/laravel-pg-extensions": "^5.3"
|
"umbrellio/laravel-pg-extensions": "^5.3",
|
||||||
|
"ext-fileinfo": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.9.1",
|
"fakerphp/faker": "^1.9.1",
|
||||||
|
|||||||
@ -15,7 +15,8 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('info_sectorial', function (Blueprint $table) {
|
Schema::create('info_sectorial', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('title');
|
$table->string('uid')->unique()->index();
|
||||||
|
$table->string('name');
|
||||||
$table->string('path');
|
$table->string('path');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->softDeletes();
|
$table->softDeletes();
|
||||||
|
|||||||
@ -42,7 +42,7 @@ Route::middleware(['auth:sanctum', 'ability:Admin'])->group(function () {
|
|||||||
Route::post('faq', [\App\Http\Controllers\FaqController::class, 'store']);
|
Route::post('faq', [\App\Http\Controllers\FaqController::class, 'store']);
|
||||||
Route::delete('faq/{faq}', [\App\Http\Controllers\FaqController::class, 'destroy']);
|
Route::delete('faq/{faq}', [\App\Http\Controllers\FaqController::class, 'destroy']);
|
||||||
|
|
||||||
Route::post('updateFile', [\App\Http\Controllers\InfoSectorialController::class, 'updateFile']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
||||||
@ -60,6 +60,7 @@ Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
|||||||
Route::post('operation/summary', [\App\Http\Controllers\OperationSummaryController::class, 'operationSummary']);
|
Route::post('operation/summary', [\App\Http\Controllers\OperationSummaryController::class, 'operationSummary']);
|
||||||
Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'index']);
|
Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'index']);
|
||||||
|
|
||||||
|
Route::post('updateFile', [\App\Http\Controllers\InfoSectorialController::class, 'updateFile']);
|
||||||
Route::get('download', [\App\Http\Controllers\InfoSectorialController::class, 'download']);
|
Route::get('download', [\App\Http\Controllers\InfoSectorialController::class, 'download']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user