add file download with hashed name
This commit is contained in:
parent
59689d670e
commit
bf232ef382
|
@ -44,23 +44,26 @@ class FileController extends Controller
|
|||
{
|
||||
abort_if(Auth::guest(), 403);
|
||||
|
||||
$content = $request->file('url');
|
||||
WorkWithFiles::saveFileToUploads($content);
|
||||
$newPath = WorkWithFiles::renameFile($content);
|
||||
|
||||
$url = $request->file('file');
|
||||
$return = Storage::put('file.jpg', $content);
|
||||
dd($return);
|
||||
$nameFile = $request->file('url')->getClientOriginalName();
|
||||
$name = Storage::put('public', $request->file('url'));
|
||||
|
||||
$validated = $request->validated();
|
||||
$file = new File();
|
||||
$file->name = $validated['name'];
|
||||
$file->url = $newPath;
|
||||
$file->file_name = $nameFile;
|
||||
$file->url = Storage::url($name);
|
||||
$file->position = $validated['position'];
|
||||
$file->reception_screen_id = $validated['idReceptionScreen'];
|
||||
$file->save();
|
||||
|
||||
return redirect()->route('files.index');
|
||||
}
|
||||
|
||||
public function download($id)
|
||||
{
|
||||
$file = (new File())->find($id);
|
||||
return Storage::url($file->url);
|
||||
}
|
||||
public function edit(int $idFile)
|
||||
{
|
||||
abort_if(Auth::guest(), 403);
|
||||
|
|
|
@ -13,8 +13,9 @@ class File extends Model
|
|||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'file_name',
|
||||
'url',
|
||||
'description'
|
||||
'description',
|
||||
];
|
||||
|
||||
public function receptionScreen(): BelongsTo
|
||||
|
|
|
@ -14,6 +14,7 @@ return new class extends Migration
|
|||
Schema::create('files', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('file_name');
|
||||
$table->string('description')->nullable();
|
||||
$table->string('url');
|
||||
$table->integer('position');
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
</div>
|
||||
@foreach($receptionScreen->files as $file)
|
||||
<div class="col-8">
|
||||
<a href="{{ $file->url }}">{{ $file->name }}</a>
|
||||
<a href="{{ $file->url }}" target="_blank">{{ $file->name }}</a>
|
||||
</div>
|
||||
@endforeach
|
||||
@endforeach
|
||||
|
|
|
@ -30,6 +30,7 @@ Route::get('/files/create/{file?}', [FileController::class, 'create'])->name('fi
|
|||
Route::patch('/files/{file}', [FileController::class, 'update'])->name('files.update');
|
||||
Route::delete('files/{file}', [FileController::class, 'destroy'])->name('files.destroy');
|
||||
Route::get('/files/edit/{file}', [FileController::class, 'edit'])->name('files.edit');
|
||||
Route::get('/files/download/{file}', [FileController::class, 'download'])->name('files.download');
|
||||
|
||||
Route::get('/course', function () {
|
||||
return view('menu.course');
|
||||
|
|
Loading…
Reference in New Issue