You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Jobs\RecreateDocument;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class RecreateDocumentController extends Controller
|
|
{
|
|
public function store()
|
|
{
|
|
request()->validate([
|
|
'id' => 'required',
|
|
'data' => 'required',
|
|
]);
|
|
|
|
$id = request()->get('id');
|
|
$data = json_decode(request()->get('data'), true);
|
|
|
|
try {
|
|
RecreateDocument::dispatch($id, $data);
|
|
|
|
return response()->json([
|
|
'status' => 'processing',
|
|
]);
|
|
} catch (\Exception $exception) {
|
|
return response()->json([
|
|
'status' => 'fail',
|
|
'message' => $exception->getMessage(),
|
|
], 400);
|
|
}
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
request()->validate([
|
|
'file_path' => 'required',
|
|
]);
|
|
|
|
$filePath = request()->get('file_path');
|
|
$storage = Storage::disk('local');
|
|
|
|
$fullPath = 'contracts/' . $id . '-' . $filePath;
|
|
|
|
if ( ! $storage->exists($fullPath)) {
|
|
return '';
|
|
}
|
|
|
|
return response()->download($storage->path($fullPath), $filePath, [])
|
|
->deleteFileAfterSend(true);
|
|
}
|
|
}
|