Created
November 19, 2017 18:06
-
-
Save jackbarham/01f8e2d9fcbe4daac5c9e73df99bc457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Models\User; | |
use App\Models\Page; | |
use App\Models\NewsItem; | |
use App\Models\VideoItem; | |
use App\Models\AudioItem; | |
use App\Models\GalleryItem; | |
use App\Models\ReleaseItem; | |
use App\Models\SliderModule; | |
class PageController extends Controller | |
{ | |
/** | |
* @param $domain | |
* @return View | |
*/ | |
public function home($domain) | |
{ | |
$user = User::where('live_domain', $domain)->first(); | |
$data = Page::where(['user_id' => $user->id, 'visibility' => 'visible']) | |
->with('modules.content') | |
->first(); | |
foreach ($data->modules as $module) { | |
if ($module->type === 'newsfeed') { | |
$newsfeed = NewsItem::where('page_id', $module->content->news_page_id) | |
->with('modules.content') | |
->limit($module->content->limit) | |
->get(); | |
} | |
if ($module->type === 'slider') { | |
$slider = SliderModule::where('id', $module->content->id) | |
->with('slideritems') | |
->first(); | |
} | |
} | |
//return compact('data', 'newsfeed', 'slider'); | |
return view($user->settings->active_theme . '.home', compact('data', 'newsfeed', 'slider')); | |
} | |
/** | |
* @param $domain | |
* @param $pageSlug | |
* @return View | |
*/ | |
public function page($domain, $pageSlug) | |
{ | |
$user = User::where('live_domain', $domain)->first(); | |
$page = Page::where(['slug' => $pageSlug, 'user_id' => $user->id])->first(); | |
$settings = $user->settings; | |
if (!$page) { | |
return view($settings->active_theme . '.' . 'errors.404', compact('data')); | |
} | |
switch ($page->type) { | |
case 'custom': | |
$data = $page->where(['slug' => $pageSlug, 'user_id' => $user->id]) | |
->with('modules.content') | |
->first(); | |
break; | |
case 'audio': | |
$data = $page->where(['slug' => $pageSlug, 'user_id' => $user->id]) | |
->with('audioitems.content') | |
->first(); | |
break; | |
case 'video': | |
$data = $page->where(['slug' => $pageSlug, 'user_id' => $user->id]) | |
->with('videoitems.content') | |
->first(); | |
break; | |
case 'gallery': | |
$data = $page->where(['slug' => $pageSlug, 'user_id' => $user->id]) | |
->with('galleryitems.content.galleryimages') | |
->first(); | |
break; | |
case 'image': | |
$data = $page->where(['slug' => $pageSlug, 'user_id' => $user->id]) | |
->with('modules.content.galleryimages') | |
->first(); | |
break; | |
case 'gig': | |
$data = $page->where(['slug' => $pageSlug, 'user_id' => $user->id]) | |
->with('gigitems.giglinks') | |
->first(); | |
break; | |
case 'release': | |
$data = $page->where(['slug' => $pageSlug, 'user_id' => $user->id]) | |
->with('releaseitems') | |
->first(); | |
break; | |
case 'news': | |
$data = $page->where(['slug' => $pageSlug, 'user_id' => $user->id]) | |
->with('newsitems.modules.content') | |
->first(); | |
break; | |
default: | |
return view($settings->active_theme . '.' . 'home'); | |
} | |
//return compact('data', 'settings'); | |
return view($user->settings->active_theme . '.' . $page->type, compact('data', 'settings')); | |
} | |
/** | |
* @param $domain | |
* @param $pageSlug | |
* @param $itemSlug | |
* @return View | |
*/ | |
public function item($domain, $pageSlug, $itemSlug) | |
{ | |
$user = User::where('live_domain', $domain)->first(); | |
$page = Page::where(['slug' => $pageSlug, 'user_id' => $user->id])->first(); | |
$settings = $user->settings; | |
switch ($page->type) { | |
case 'audio': | |
$data = AudioItem::where(['page_id' => $page->id, 'slug' => $itemSlug])->with('content')->first(); | |
if (!$data) { | |
return view($settings->active_theme . '.' . 'errors.404', compact('data')); | |
} | |
break; | |
case 'video': | |
$data = VideoItem::where(['page_id' => $page->id, 'slug' => $itemSlug])->with('content')->first(); | |
if (!$data) { | |
return view($settings->active_theme . '.' . 'errors.404', compact('data')); | |
} | |
break; | |
case 'gallery': | |
$data = GalleryItem::where(['page_id' => $page->id, 'slug' => $itemSlug])->with('content.galleryimages')->first(); | |
if (!$data) { | |
return view($settings->active_theme . '.' . 'errors.404', compact('data')); | |
} | |
break; | |
case 'release': | |
$data = ReleaseItem::where(['page_id' => $page->id, 'slug' => $itemSlug])->with('releaseclips', 'releaselinks')->first(); | |
if (!$data) { | |
return view($settings->active_theme . '.' . 'errors.404', compact('data')); | |
} | |
break; | |
case 'news': | |
$data = NewsItem::where(['page_id' => $page->id, 'slug' => $itemSlug])->with('modules.content')->first(); | |
if (!$data) { | |
return view($settings->active_theme . '.' . 'errors.404', compact('data')); | |
} | |
break; | |
default: | |
return view($settings->active_theme . '.' . 'home'); | |
} | |
//return compact('data', 'settings'); | |
return view($settings->active_theme . '.' . $page->type . '-item', compact('data', 'settings')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example fix:
I have to loop through page modules (line 24) and if those modules exist I have to recall them again (from line 27) and output them separately. I the module items to be attached to the modules. At the moment I use Blade to attach them together, but this does not work as there can be multiple versions of the same module.
I've tried
->with('modules.content.newsfeed.content.modules')
but it doesn't work.You can see this in action here: http://carlcox.vibecast.com