tethys/app/Http/Controllers/Settings/PageController.php

137 lines
3.5 KiB
PHP
Raw Permalink Normal View History

2018-09-04 14:51:04 +00:00
<?php
namespace App\Http\Controllers\Settings;
use App\Models\Page;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Pages\IndexPageRequest;
2018-09-06 15:58:54 +00:00
use App\Http\Requests\Pages\UpdatePageRequest;
use Illuminate\View\View;
use Illuminate\Http\RedirectResponse;
use App\Exceptions\GeneralException;
use App\Events\Pages\PageUpdated;
2018-09-12 15:30:42 +00:00
use Illuminate\Support\Facades\DB;
2018-09-04 14:51:04 +00:00
class PageController extends Controller
{
2018-09-06 15:58:54 +00:00
/**
* Associated Repository Model.
*/
const MODEL = Page::class;
2018-09-04 14:51:04 +00:00
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
2018-09-06 15:58:54 +00:00
public function index(IndexPageRequest $request): View
2018-09-04 14:51:04 +00:00
{
2018-09-06 15:58:54 +00:00
return view('settings.page.index');
2018-09-04 14:51:04 +00:00
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Models\Page $page
* @return \Illuminate\Http\Response
*/
public function show(Page $page)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Page $page
* @return \Illuminate\Http\Response
*/
public function edit(Page $page)
{
2018-09-12 15:30:42 +00:00
$languages = DB::table('languages')
->where('active', true)
->pluck('part2_t', 'part2_t');
return view('settings.page.edit', compact('page', 'languages'));
// ->withPage($page);
2018-09-04 14:51:04 +00:00
}
/**
* Update the specified resource in storage.
*
2018-11-13 16:21:58 +00:00
* @param \App\Http\Requests\Pages\UpdatePageRequest $request
* @param int $id
2018-09-04 14:51:04 +00:00
* @return \Illuminate\Http\Response
*/
2018-11-13 16:21:58 +00:00
public function update(UpdatePageRequest $request, $id)
2018-09-04 14:51:04 +00:00
{
2018-11-13 16:21:58 +00:00
$page = Page::findOrFail($id);
2018-09-06 15:58:54 +00:00
// $this->pages->update($page, $request->except(['_method', '_token']));
2018-11-13 16:21:58 +00:00
$input = $request
->except(['_method', '_token', 'nav-tab', 'en_title', 'en_description', 'de_title', 'de_description']);
2018-09-06 15:58:54 +00:00
// Making extra fields
2018-09-12 15:30:42 +00:00
//$input['page_slug'] = str_slug($input['title']);
2018-09-06 15:58:54 +00:00
$input['status'] = isset($input['status']) ? 1 : 0;
$input['updated_by'] = \Auth::user()->id;
2018-11-13 16:21:58 +00:00
$article_data = [
'en' => [
'title' => $request->input('en_title'),
'description' => $request->input('en_description')
],
'de' => [
'title' => $request->input('de_title'),
'description' => $request->input('de_description')
],
];
$ergebnis = array_merge($input, $article_data);
if ($page->update($ergebnis)) {
2018-09-06 15:58:54 +00:00
event(new PageUpdated($page));
return redirect()
->route('settings.page.index')
->with('flash_message', trans('alerts.backend.pages.updated'));
}
throw new GeneralException(trans('exceptions.backend.pages.update_error'));
2018-09-04 14:51:04 +00:00
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Page $page
* @return \Illuminate\Http\Response
*/
public function destroy(Page $page)
{
//
}
2018-09-06 15:58:54 +00:00
public function query()
{
return call_user_func(static::MODEL.'::query');
}
2018-09-04 14:51:04 +00:00
}