92 lines
2.2 KiB
PHP
92 lines
2.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Admin;
|
||
|
|
||
|
use App\Facade\Theme;
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use App\Http\Requests\StoreLabelRequest;
|
||
|
use App\Label;
|
||
|
use Illuminate\Support\Facades\App;
|
||
|
use Illuminate\Support\Facades\View;
|
||
|
use Symfony\Component\HttpFoundation\Request;
|
||
|
|
||
|
class LabelController extends Controller
|
||
|
{
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->middleware(['auth', 'max_post_size_exceeded']);
|
||
|
View::share('is_admin', true);
|
||
|
}
|
||
|
|
||
|
public function delete($id)
|
||
|
{
|
||
|
$this->authorizeAccessToAdminPanel();
|
||
|
|
||
|
$label = $this->loadLabel($id);
|
||
|
return Theme::render('admin.delete_label', ['label' => $label]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Remove the specified resource from storage.
|
||
|
*
|
||
|
* @param int $id
|
||
|
* @return \Illuminate\Http\Response
|
||
|
*/
|
||
|
public function destroy(Request $request, $id)
|
||
|
{
|
||
|
$this->authorizeAccessToAdminPanel('admin:manage-labels');
|
||
|
|
||
|
$label = $this->loadLabel($id);
|
||
|
$label->delete();
|
||
|
|
||
|
$request->session()->flash('success', trans('admin.delete_label_success_message', ['name' => $label->name]));
|
||
|
|
||
|
return redirect(route('labels.index'));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Display a listing of the resource.
|
||
|
*
|
||
|
* @return \Illuminate\Http\Response
|
||
|
*/
|
||
|
public function index()
|
||
|
{
|
||
|
$labels = Label::withCount('photos')->get();
|
||
|
return Theme::render('admin.list_labels', [
|
||
|
'labels' => $labels
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Store a newly created resource in storage.
|
||
|
*
|
||
|
* @param \Illuminate\Http\Request $request
|
||
|
* @return \Illuminate\Http\Response
|
||
|
*/
|
||
|
public function store(StoreLabelRequest $request)
|
||
|
{
|
||
|
$this->authorizeAccessToAdminPanel('admin:manage-labels');
|
||
|
|
||
|
$label = new Label();
|
||
|
$label->fill($request->only(['name']));
|
||
|
$label->save();
|
||
|
|
||
|
return redirect(route('labels.index'));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param $id
|
||
|
* @return Album
|
||
|
*/
|
||
|
private function loadLabel($id)
|
||
|
{
|
||
|
$label = Label::where('id', intval($id))->first();
|
||
|
if (is_null($label))
|
||
|
{
|
||
|
App::abort(404);
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
return $label;
|
||
|
}
|
||
|
}
|