Skip to content

Commit

Permalink
page route added
Browse files Browse the repository at this point in the history
  • Loading branch information
Cipfahim committed Jun 8, 2020
1 parent 649173b commit ed8ccdc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\PageResource;
use App\Models\Page;

class PageController extends Controller
{
/**
* Handle the incoming request.
*
* @param $slug
* @return \Illuminate\Http\Response
*/
public function __invoke($slug)
{
return Page::findBySlug($slug);
}
}
11 changes: 11 additions & 0 deletions app/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ public function registerMediaCollections() : void
->useFallbackPath(config('app.placeholder').'800.png');
}

/**
* Find page by slug.
*
* @param $slug
* @return mixed
*/
public static function findBySlug($slug)
{
return self::where('slug',$slug)->firstOrFail();
}

/**
* Scope a query to only include active pages.
*
Expand Down
2 changes: 1 addition & 1 deletion resources/views/backend/pages/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<td class="text-center text-muted">#{{ $key + 1 }}</td>
<td style="width: 30%">{{ $page->title }}</td>
<td>
<a href="#" target="_blank">
<a href="{{ route('page',$page->slug) }}" target="_blank">
{{ $page->slug }}
</a>
</td>
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@

});
});

// Pages route e.g. [about,contact,etc]
Route::get('/{slug}', 'PageController')->name('page');

0 comments on commit ed8ccdc

Please sign in to comment.