FEATURE #1420: add functionality for editing widget area
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests;
|
||||||
|
use App\Http\Requests\EditWidgetAreaRequest;
|
||||||
|
use App\Models\WidgetArea;
|
||||||
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
|
|
||||||
|
class EditWidgetArea extends Controller
|
||||||
|
{
|
||||||
|
public function getEdit($id)
|
||||||
|
{
|
||||||
|
$area = WidgetArea::findOrFail($id);
|
||||||
|
|
||||||
|
return view('admin.widgets.area.edit', ['area' => $area]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->route('widgetareas.edit', ['id' => $id])
|
||||||
|
->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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete area
|
||||||
|
$area->delete();
|
||||||
|
|
||||||
|
// 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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class EditWidgetAreaRequest extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@extends('admin.layout')
|
||||||
|
|
||||||
|
@section('pageName', @trans('admin/widgetAreas.edit', ['name' => $area->name]))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h1>@lang('admin/widgetAreas.edit', ['name' => $area->name])</h1>
|
||||||
|
|
||||||
|
@include('admin.widgets.area.editForm')
|
||||||
|
@stop
|
||||||
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
@if (session('success'))
|
||||||
|
<div class="callout success">
|
||||||
|
{{ session('success') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if (session('error'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ session('error') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form action="{{route('widgetareas.postEdit', ['id' => $area->id])}}" method="POST">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
<label>
|
||||||
|
@lang('admin/widgetAreas.name')
|
||||||
|
|
||||||
|
<input type="text" name="name" value="{{$area->name}}" placeholder="@lang('admin/widgetAreas.name')" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('name'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('name') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('admin/widgetAreas.code')
|
||||||
|
|
||||||
|
<input type="text" name="code" disabled="true" value="{{$area->code}}"
|
||||||
|
placeholder="@lang('admin/widgetAreas.code')" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('admin/widgetAreas.description')
|
||||||
|
|
||||||
|
<textarea rows="3" name="description"
|
||||||
|
placeholder="@lang('admin/widgetAreas.description')">{{$area->description}}</textarea>
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('description'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('description') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button type="submit" class="button success">@lang('admin/widgetAreas.editButton')</button>
|
||||||
|
</form>
|
||||||
Reference in New Issue
Block a user