refactoring delete not used elements
This commit is contained in:
parent
afebc7ea6c
commit
b07fb7648f
|
@ -51,10 +51,7 @@ class DepartmentController extends Controller
|
|||
return view('catalog.department.edit', compact('department', 'faculties'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdateDepartmentRequest $request, Department $department)
|
||||
public function update(UpdateDepartmentRequest $request, Department $department): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
|
@ -69,6 +66,9 @@ class DepartmentController extends Controller
|
|||
|
||||
public function destroy(Department $department): RedirectResponse
|
||||
{
|
||||
if ($department->directions()->exists()) {
|
||||
return back();
|
||||
}
|
||||
$department->delete();
|
||||
return redirect()->route('departments.index');
|
||||
}
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
namespace App\Http\Controllers\Catalog;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreDepartmentRequest;
|
||||
use App\Http\Requests\StoreDirectionRequest;
|
||||
use App\Http\Requests\UpdateDepartmentRequest;
|
||||
use App\Http\Requests\UpdateDirectionRequest;
|
||||
use App\Models\Department;
|
||||
use App\Models\Direction;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
|
@ -54,10 +52,7 @@ class DirectionController extends Controller
|
|||
return view('catalog.direction.edit', compact('direction', 'departments'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdateDepartmentRequest $request, Direction $direction)
|
||||
public function update(UpdateDepartmentRequest $request, Direction $direction): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ 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\Documents;
|
||||
use App\Models\ReceptionScreen;
|
||||
use App\Services\WorkWithFiles;
|
||||
use Carbon\Carbon;
|
||||
|
@ -18,16 +18,12 @@ use Illuminate\Support\Facades\Storage;
|
|||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
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'));
|
||||
$files = Documents::all()->sortBy('position');
|
||||
return view('documents.index', compact('files'));
|
||||
}
|
||||
|
||||
public function create($idReceptionScreen = null): View
|
||||
|
@ -35,7 +31,7 @@ class DocumentController extends Controller
|
|||
abort_if(Auth::guest(), 403);
|
||||
|
||||
$receptionScreens = ReceptionScreen::pluck('name', 'id');
|
||||
$files = File::where('reception_screen_id', '=', $idReceptionScreen)->get();
|
||||
$files = Documents::where('reception_screen_id', '=', $idReceptionScreen)->get();
|
||||
return view('files.create', compact('receptionScreens', 'idReceptionScreen', 'files'));
|
||||
}
|
||||
|
||||
|
@ -47,7 +43,7 @@ class DocumentController extends Controller
|
|||
$name = Storage::put('public', $request->file('url'));
|
||||
|
||||
$validated = $request->validated();
|
||||
$file = new File();
|
||||
$file = new Documents();
|
||||
$file->name = $validated['name'];
|
||||
$file->file_name = $nameFile;
|
||||
$file->url = Storage::url($name);
|
||||
|
@ -60,15 +56,15 @@ class DocumentController extends Controller
|
|||
|
||||
public function download($id)
|
||||
{
|
||||
$file = (new File())->find($id);
|
||||
$file = (new Documents())->find($id);
|
||||
return Storage::url($file->url);
|
||||
}
|
||||
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();
|
||||
$file = (new Documents())->find($idFile);
|
||||
$files = Documents::where('reception_screen_id', '=', $file->reception_screen_id)->get();
|
||||
|
||||
$receptionScreens = ReceptionScreen::pluck('name', 'id');
|
||||
$idsReceptionScreens = $receptionScreens->keys()->toArray();
|
||||
|
@ -85,7 +81,7 @@ class DocumentController extends Controller
|
|||
);
|
||||
}
|
||||
|
||||
public function update(UpdateFileRequest $request, File $file)
|
||||
public function update(UpdateFileRequest $request, Documents $file)
|
||||
{
|
||||
abort_if(Auth::guest(), 403);
|
||||
|
||||
|
@ -102,7 +98,7 @@ class DocumentController extends Controller
|
|||
{
|
||||
abort_if(Auth::guest(), 403);
|
||||
|
||||
$file = (new File())->find($idFile);
|
||||
$file = (new Documents())->find($idFile);
|
||||
$file->delete();
|
||||
return redirect()->route('admin-reception-screen.index');
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Department extends Model
|
||||
{
|
||||
|
@ -21,4 +22,9 @@ class Department extends Model
|
|||
{
|
||||
return $this->belongsTo(Faculty::class);
|
||||
}
|
||||
|
||||
public function directions(): HasMany
|
||||
{
|
||||
return $this->hasMany('App\Models\Direction', 'department_id');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue