73 lines
2.7 KiB
PHP
73 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin\Catalog;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\admin\StoreDirectionDescriptionRequest;
|
|
use App\Http\Requests\admin\UpdateDirectionDescriptionRequest;
|
|
use App\Models\Direction;
|
|
use App\Models\DirectionDescription;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class DirectionDescriptionController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$directionDescriptions = DirectionDescription::all();
|
|
return view('admin.catalog.direction_description.index', compact('directionDescriptions'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$directionCodes = Direction::pluck('full_name', 'code');
|
|
return view('admin.catalog.direction_description.create', compact('directionCodes'));
|
|
}
|
|
|
|
public function store(StoreDirectionDescriptionRequest $request)
|
|
{
|
|
$validated = $request->validated();
|
|
$fileName = $request->file('file')->getClientOriginalName();
|
|
$name = Storage::put('public', $request->file('file'));
|
|
|
|
$directionDescription = new DirectionDescription();
|
|
$directionDescription->url = Storage::url($name);
|
|
$directionDescription->direction_code = Direction::select('code', 'id')
|
|
->where('code', $validated['direction_code'])
|
|
->first()
|
|
->id;
|
|
$directionDescription->file_name = $fileName;
|
|
$directionDescription->position = $validated['position'];
|
|
$directionDescription->save();
|
|
return redirect()->route('direction_descriptions.index');
|
|
}
|
|
|
|
public function edit(DirectionDescription $directionDescription)
|
|
{
|
|
$directionCodes = Direction::pluck('full_name', 'code');
|
|
return view('admin.catalog.direction_description.edit', compact('directionDescription', 'directionCodes'));
|
|
}
|
|
|
|
public function update(UpdateDirectionDescriptionRequest $request, DirectionDescription $directionDescription)
|
|
{
|
|
$validated = $request->validated();
|
|
$fileName = $request->file('file')->getClientOriginalName();
|
|
$name = Storage::put('public', $request->file('file'));
|
|
|
|
$directionDescription->url = Storage::url($name);
|
|
$directionDescription->direction_code = Direction::select('code', 'id')
|
|
->where('code', $validated['direction_code'])
|
|
->first()
|
|
->id;
|
|
$directionDescription->file_name = $fileName;
|
|
$directionDescription->position = $validated['position'];
|
|
$directionDescription->save();
|
|
return redirect()->route('direction_descriptions.index');
|
|
}
|
|
|
|
public function destroy(DirectionDescription $directionDescription)
|
|
{
|
|
$directionDescription->delete();
|
|
return redirect()->route('direction_descriptions.index');
|
|
}
|
|
}
|