/**
  *   Return a view showing one of the pages
  *
  * @param String $slug - if numeric will be treated as an id, otherwise will search for matching slug
  * @param String $pageSlug - if numeric will be treated as an id, otherwise will search for matching slug
  * @return View - returns created page, or throws a 404 if slug is invalid or can't find a matching record
  */
 public function page($slug, $pageSlug)
 {
     // Build query to find relevent Project
     $query = Project::where('slug', '=', $slug)->with('pages');
     $project = $query->first();
     // Check if a project was found
     if ($project == null) {
         return abort('404', 'Invalid project slug');
     } else {
         // Filter related pages and return the one with the correct slug
         $filteredPages = $project->pages->filter(function ($page) use($pageSlug) {
             if (isset($page->slug) && $page->slug == $pageSlug) {
                 return $page;
             }
         });
         $page = $filteredPages->first();
         // Check if a page was found
         if ($page != null) {
             if ($page->template == null || $page->template == 'default') {
                 $template = 'portfolio::page';
             } else {
                 $template = 'portfolio::pages.' . $page->template;
             }
             // Return view with projects
             return view($template)->with(['page' => $page, 'project' => $project]);
         } else {
             // No project found, throw a 404.
             return abort('404', 'Invalid page slug');
         }
     }
 }
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     $projects = Project::where('featured', '=', '1')->orderBy('created_at', 'DESC')->take(3)->get();
     $view->with('projects', $projects);
 }