Created
September 4, 2012 20:29
-
-
Save shakyShane/3626105 to your computer and use it in GitHub Desktop.
Create a Permalink from a page title - Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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