php – Laravel Page Controller


Aim: To make pages located in site.com/page-1, site.com/page-2. Those pages are pretty much static so I won’t use database.

First, I’ve created the PageController.

class PageController extends Controller
{

 public function page($slug)
 {
  $page = $this->pageContents($slug);
  return view('page', ('page' => $page));
 }

 public function pageContents($slug)
 {
  $page = ();
  $page("slug") = $slug;
  if ($slug == "page-1") {
   $page("title") = "Page 1";
   $page("content") = "Content..";
  }

  if ($slug == "page-2") {
   $page("title") = "Page 2";
   $page("content") = "Content..";
  }  

  return $page;
 }
}

web.php (Routes):

Route::get('/{page-1}', 'PageController@page')->name('page-1');
Route::get('/{page-2}', 'PageController@page')->name('page-2');

Would appreciate any reviews!