Skip to content

Instantly share code, notes, and snippets.

@shakyShane
Created September 4, 2012 20:29
Show Gist options
  • Save shakyShane/3626105 to your computer and use it in GitHub Desktop.
Save shakyShane/3626105 to your computer and use it in GitHub Desktop.
Create a Permalink from a page title - Laravel
<?php
class Category extends Eloquent
{
/**
* -----------------------------------
* Make Permalink from a Title.
* -----------------------------------
*
* Take this [ Fence Panels ]
* Return this [ /prefix/12/fence-panels ]
* Where :
* '/prefix' = The controlling route.
* '/12' = The ID of the element in the DB
* 'fence-panels' = the Page/Product Title
*
* This removes the need to perform any CRUD actions for Permalinks.
*
* @param null $prefix
* @return string
*
* //TODO Check for characters that would screw up the route. Such as / & \
*
*/
public function makePermalink($prefix = null){
$defaultPrefix = ($prefix) ? $prefix : '/online-brochure';
return $defaultPrefix . '/' . $this->id . '/' . str_replace(' ', '-',trim($this->name));
}//makePermalink()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment