154 lines
3.9 KiB
PHP
154 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Request;
|
|
use Carbon\Carbon;
|
|
use App\Models\Page;
|
|
|
|
class TravelContentController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware(['admin', '2fa']);
|
|
}
|
|
|
|
public function index($step = false)
|
|
{
|
|
$data = [
|
|
'travelProgramOverviews' => Page::whereTemplate('travelProgramOverview')->get(),
|
|
'step' => $step
|
|
];
|
|
return view('travel.content.index', $data);
|
|
|
|
|
|
}
|
|
|
|
public function detail($id)
|
|
{
|
|
if($id === "new") {
|
|
$id = 'new';
|
|
|
|
}else{
|
|
$page = Page::findOrFail($id);
|
|
$id = $page->id;
|
|
}
|
|
$data = [
|
|
'model' => $page,
|
|
'id' => $id,
|
|
];
|
|
return view('travel.content.detail', $data);
|
|
}
|
|
|
|
public function store($id)
|
|
{
|
|
$data = Request::all();
|
|
if($id === "new") {
|
|
//$draft = new Draft();
|
|
}else{
|
|
$page = Page::findOrFail($id);
|
|
}
|
|
|
|
if(Page::whereSlug($data['slug'])->where('id', '!=', $page->id)->count() > 0){
|
|
$data['slug'] = "";
|
|
}
|
|
|
|
$page->title = $data['title'];
|
|
$page->title_short = $data['title_short'];
|
|
$page->pagetitle = $data['pagetitle'];
|
|
$page->slug = $data['slug'];
|
|
$page->description = $data['description'];
|
|
$page->content_new = $data['content_new'];
|
|
$page->status = $data['status'];
|
|
$page->show_in_navi = $data['show_in_navi'];
|
|
$page->save();
|
|
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('travel_content_detail', [$page->id]));
|
|
}
|
|
|
|
public function subDetail($id)
|
|
{
|
|
if($id === "new") {
|
|
$id = 'new';
|
|
|
|
}else{
|
|
$page = Page::findOrFail($id);
|
|
$id = $page->id;
|
|
}
|
|
$data = [
|
|
'model' => $page,
|
|
'id' => $id,
|
|
];
|
|
return view('travel.content.sub_detail', $data);
|
|
}
|
|
|
|
public function subStore($id)
|
|
{
|
|
$data = Request::all();
|
|
if($id === "new") {
|
|
//$draft = new Draft();
|
|
}else{
|
|
$page = Page::findOrFail($id);
|
|
}
|
|
|
|
if(Page::whereSlug($data['slug'])->where('id', '!=', $page->id)->count() > 0){
|
|
$data['slug'] = "";
|
|
}
|
|
$page->title = $data['title'];
|
|
$page->pagetitle = $data['pagetitle'];
|
|
$page->slug = $data['slug'];
|
|
$page->description = $data['description'];
|
|
$page->status = $data['status'];
|
|
$page->show_in_navi = $data['show_in_navi'];
|
|
$page->order = $data['order'];
|
|
|
|
$page->travel_program = $data['travel_program'] > 0 ? $data['travel_program'] : null;
|
|
|
|
$page->save();
|
|
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('travel_content_sub_detail', [$page->id]));
|
|
}
|
|
|
|
|
|
public function load(){
|
|
$data = Request::all();
|
|
$ret = "";
|
|
if(Request::ajax()) {
|
|
if($data['action'] === "modal-copy-page") {
|
|
if($data['id'] > 0){
|
|
$value = Page::findOrFail($data['id']);
|
|
$ret = view('travel.content.modal_copy', compact('value'))->render();
|
|
}
|
|
}
|
|
}
|
|
return response()->json(['response' => $data, 'html'=>$ret]);
|
|
}
|
|
|
|
|
|
|
|
public function update(){
|
|
|
|
$data = Request::all();
|
|
|
|
if($data['action'] === 'page-copy'){
|
|
if($data['page_copy_id'] > 0){
|
|
$model = Page::findOrFail($data['page_copy_id']);
|
|
$newModel = $model->replicate();
|
|
$newModel->date = null;
|
|
//slug unique
|
|
// $newModel->slug
|
|
$newModel->created_at = now();
|
|
$newModel->save();
|
|
}
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('travel_content_detail', [$data['id']]));
|
|
}
|
|
}
|
|
}
|
|
|
|
|