92 lines
2 KiB
PHP
Executable file
92 lines
2 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\CMS;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\CMSAuthor;
|
|
use Request;
|
|
use Validator;
|
|
|
|
|
|
class CMSContentAuthorController extends Controller
|
|
{
|
|
|
|
/*
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware(['admin', '2fa']);
|
|
}
|
|
|
|
|
|
public function index()
|
|
{
|
|
$data = [
|
|
'contents' => CMSAuthor::all()->sortByDesc('id')
|
|
];
|
|
return view('cms.content.author.index', $data);
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
$data = Request::all();
|
|
$rules = array(
|
|
'name' => 'required',
|
|
);
|
|
$validator = Validator::make(Request::all(), $rules);
|
|
|
|
if ($validator->fails()) {
|
|
return back()->withErrors($validator);
|
|
}
|
|
|
|
if($data['id'] === "new"){
|
|
CMSAuthor::create($data);
|
|
}else{
|
|
|
|
$model = CMSAuthor::find($data['id']);
|
|
$model->fill($data);
|
|
$model->save();
|
|
}
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('cms_content_author'));
|
|
}
|
|
|
|
|
|
public function loadModal()
|
|
{
|
|
if(Request::ajax()){
|
|
$data = Request::all();
|
|
$returnHTML = "";
|
|
if(isset($data['model']) && isset($data['id']) ){
|
|
if($data['model'] === 'content'){
|
|
if($data['id'] === "new"){
|
|
$value = new CMSAuthor();
|
|
}else {
|
|
$value = CMSAuthor::find($data['id']);
|
|
}
|
|
$returnHTML = view("cms.content.author.modal", compact('data','value') )->render();
|
|
}
|
|
|
|
}
|
|
return response()->json(['response' => $data, 'html'=>$returnHTML]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function delete($id){
|
|
$content = CMSAuthor::findOrFail($id);
|
|
$content->delete();
|
|
\Session()->flash('alert-success', __('Autor gelöscht'));
|
|
return redirect(route('cms_content_author'));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|