2024-01-26 11:15:11 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\StoreFileRequest;
|
|
|
|
use App\Http\Requests\StoreReceptionScreenRequest;
|
|
|
|
use App\Http\Requests\UpdateFileRequest;
|
|
|
|
use App\Http\Requests\UpdateReceptionScreenRequest;
|
|
|
|
use App\Models\File;
|
|
|
|
use App\Models\ReceptionScreen;
|
|
|
|
use App\Services\WorkWithFiles;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Foundation\Application;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2024-01-30 10:55:31 +03:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2024-01-26 11:15:11 +03:00
|
|
|
|
2024-02-09 14:31:12 +03:00
|
|
|
class DocumentController extends Controller
|
2024-01-26 11:15:11 +03:00
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
|
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
|
|
|
|
$files = File::all()->sortBy('position');
|
|
|
|
return view('files.index', compact('files'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create($idReceptionScreen = null): View
|
|
|
|
{
|
|
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
|
|
|
|
$receptionScreens = ReceptionScreen::pluck('name', 'id');
|
|
|
|
$files = File::where('reception_screen_id', '=', $idReceptionScreen)->get();
|
2024-02-07 16:33:34 +03:00
|
|
|
return view('files.create', compact('receptionScreens', 'idReceptionScreen', 'files'));
|
2024-01-26 11:15:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(StoreFileRequest $request)
|
|
|
|
{
|
|
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
|
2024-01-31 08:47:05 +03:00
|
|
|
$nameFile = $request->file('url')->getClientOriginalName();
|
|
|
|
$name = Storage::put('public', $request->file('url'));
|
2024-01-30 10:55:31 +03:00
|
|
|
|
2024-01-26 11:15:11 +03:00
|
|
|
$validated = $request->validated();
|
|
|
|
$file = new File();
|
|
|
|
$file->name = $validated['name'];
|
2024-01-31 08:47:05 +03:00
|
|
|
$file->file_name = $nameFile;
|
|
|
|
$file->url = Storage::url($name);
|
2024-01-26 11:15:11 +03:00
|
|
|
$file->position = $validated['position'];
|
|
|
|
$file->reception_screen_id = $validated['idReceptionScreen'];
|
|
|
|
$file->save();
|
2024-01-31 08:47:05 +03:00
|
|
|
|
2024-01-26 11:15:11 +03:00
|
|
|
return redirect()->route('files.index');
|
|
|
|
}
|
2024-01-31 08:47:05 +03:00
|
|
|
|
|
|
|
public function download($id)
|
|
|
|
{
|
|
|
|
$file = (new File())->find($id);
|
|
|
|
return Storage::url($file->url);
|
|
|
|
}
|
2024-01-26 11:15:11 +03:00
|
|
|
public function edit(int $idFile)
|
|
|
|
{
|
|
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
|
|
|
|
$file = (new File())->find($idFile);
|
|
|
|
$files = File::where('reception_screen_id', '=', $file->reception_screen_id)->get();
|
|
|
|
|
|
|
|
$receptionScreens = ReceptionScreen::pluck('name', 'id');
|
|
|
|
$idsReceptionScreens = $receptionScreens->keys()->toArray();
|
|
|
|
$idReceptionScreen = $file->reception_screen_id;
|
2024-01-29 09:44:53 +03:00
|
|
|
return view(
|
|
|
|
'files.edit',
|
|
|
|
compact(
|
|
|
|
'receptionScreens',
|
|
|
|
'idsReceptionScreens',
|
|
|
|
'idReceptionScreen',
|
|
|
|
'files',
|
|
|
|
'file'
|
|
|
|
)
|
|
|
|
);
|
2024-01-26 11:15:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function update(UpdateFileRequest $request, File $file)
|
|
|
|
{
|
|
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
|
|
|
$file->name = $validated['name'];
|
|
|
|
$file->position = $validated['position'];
|
|
|
|
$file->reception_screen_id = $validated['idReceptionScreen'];
|
|
|
|
$file->save();
|
|
|
|
return redirect()->route('admin-reception-screen.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy($idFile)
|
|
|
|
{
|
|
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
|
|
|
|
$file = (new File())->find($idFile);
|
|
|
|
$file->delete();
|
|
|
|
return redirect()->route('admin-reception-screen.index');
|
|
|
|
}
|
|
|
|
}
|