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