123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Models\Page;
- use App\Models\PageTranslation;
- class PageController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- return view('backend.website_settings.pages.create');
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- $page = new Page;
- $page->title = $request->title;
- if (Page::where('slug', preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->slug)))->first() == null) {
- $page->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->slug));
- $page->type = "custom_page";
- $page->content = $request->content;
- $page->meta_title = $request->meta_title;
- $page->meta_description = $request->meta_description;
- $page->keywords = $request->keywords;
- $page->meta_image = $request->meta_image;
- $page->save();
- $page_translation = PageTranslation::firstOrNew(['lang' => env('DEFAULT_LANGUAGE'), 'page_id' => $page->id]);
- $page_translation->title = $request->title;
- $page_translation->content = $request->content;
- $page_translation->save();
- flash(translate('New page has been created successfully'))->success();
- return redirect()->route('website.pages');
- }
- flash(translate('Slug has been used already'))->warning();
- return back();
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- //
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function edit(Request $request, $id)
- {
- $lang = $request->lang;
- $page_name = $request->page;
- $page = Page::where('slug', $id)->first();
- if($page != null){
- if ($page_name == 'home') {
- return view('backend.website_settings.pages.home_page_edit', compact('page','lang'));
- }
- else{
- return view('backend.website_settings.pages.edit', compact('page','lang'));
- }
- }
- abort(404);
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- $page = Page::findOrFail($id);
- if (Page::where('id','!=', $id)->where('slug', preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->slug)))->first() == null) {
- if($page->type == 'custom_page'){
- $page->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->slug));
- }
- if($request->lang == env("DEFAULT_LANGUAGE")){
- $page->title = $request->title;
- $page->content = $request->content;
- }
- $page->meta_title = $request->meta_title;
- $page->meta_description = $request->meta_description;
- $page->keywords = $request->keywords;
- $page->meta_image = $request->meta_image;
- $page->save();
- $page_translation = PageTranslation::firstOrNew(['lang' => $request->lang, 'page_id' => $page->id]);
- $page_translation->title = $request->title;
- $page_translation->content = $request->content;
- $page_translation->save();
- flash(translate('Page has been updated successfully'))->success();
- return redirect()->route('website.pages');
- }
- flash(translate('Slug has been used already'))->warning();
- return back();
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- $page = Page::findOrFail($id);
- foreach ($page->page_translations as $key => $page_translation) {
- $page_translation->delete();
- }
- if(Page::destroy($id)){
- flash(translate('Page has been deleted successfully'))->success();
- return redirect()->back();
- }
- return back();
- }
- public function show_custom_page($slug){
- $page = Page::where('slug', $slug)->first();
- if($page != null){
- return view('frontend.custom_page', compact('page'));
- }
- abort(404);
- }
- public function mobile_custom_page($slug){
- $page = Page::where('slug', $slug)->first();
- if($page != null){
- return view('frontend.m_custom_page', compact('page'));
- }
- abort(404);
- }
- }
|