94 lines
2.4 KiB
PHP
94 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\EditWidgetAreaRequest;
|
|
use App\Models\WidgetArea;
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
class EditWidgetArea extends Controller
|
|
{
|
|
public function getEdit($id)
|
|
{
|
|
$area = WidgetArea::findOrFail($id);
|
|
|
|
return view('admin.widgets.area.edit', ['area' => $area]);
|
|
}
|
|
|
|
/**
|
|
* @param EditWidgetAreaRequest $request
|
|
* @param $id
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function postEdit(EditWidgetAreaRequest $request, $id)
|
|
{
|
|
try {
|
|
$area = WidgetArea::findOrFail($id);
|
|
} catch (ModelNotFoundException $e) {
|
|
return $this->invalidArea();
|
|
}
|
|
|
|
$area->name = $request->name;
|
|
$area->description = $request->description;
|
|
|
|
$area->save();
|
|
|
|
// fire event with new widget area
|
|
Event::fire(new \App\Events\EditWidgetArea($area));
|
|
|
|
return redirect()
|
|
->route('widgetareas.overview')
|
|
->with('success', trans('admin/widgetAreas.editSuccessfull'));
|
|
}
|
|
|
|
/**
|
|
* Hard deletes widget area
|
|
*
|
|
* @param $id
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function deleteArea($id)
|
|
{
|
|
// try to find area
|
|
try {
|
|
$area = WidgetArea::findOrFail($id);
|
|
} catch (ModelNotFoundException $e) {
|
|
return $this->invalidArea();
|
|
}
|
|
|
|
// check if widget area is deletable
|
|
if (!$area->deletable) {
|
|
return redirect()
|
|
->back()
|
|
->with('error', trans('admin/widgetAreas.notDeletableArea'));
|
|
}
|
|
|
|
// delete area
|
|
$area->delete();
|
|
|
|
// fire event with new widget area
|
|
Event::fire(new \App\Events\DeleteWidgetArea($area));
|
|
|
|
// redirect and inform user
|
|
return redirect()
|
|
->route('widgetareas.overview')
|
|
->with('success', trans('admin/widgetAreas.successfullyDeleted'));
|
|
}
|
|
|
|
/**
|
|
* Redirect user to overview with message about invalid widget area
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
private function invalidArea()
|
|
{
|
|
return redirect()
|
|
->route('widgetareas.overview')
|
|
->with('error', trans('admin/widgetAreas.invalidArea'));
|
|
}
|
|
}
|