Skip to content

Instantly share code, notes, and snippets.

@ferdiunal
Last active October 3, 2016 21:13
Show Gist options
  • Save ferdiunal/8dd544173f554c4449e71a98f57e0652 to your computer and use it in GitHub Desktop.
Save ferdiunal/8dd544173f554c4449e71a98f57e0652 to your computer and use it in GitHub Desktop.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Page extends Model
{
protected $table = "pages";
protected $fillable = ["title",'slug','content','description','status','publish_at'];
protected $appends = [ "url" ];
public function getURLAttribute(){
$id = $this->id;
$slug = str_slug($this->title);
return route('page.show',[$date,$slug]);
}
}
<?php
Route::get('/p/{slug}-{id}',function($slug){
return $slug;
})->name('page.show');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment