PHP code example of expstudio / friendly-url

1. Go to this page and download the library: Download expstudio/friendly-url library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

expstudio / friendly-url example snippets


	'providers' => array(

		// ...

		'Expstudio\FriendlyUrl\SluggableServiceProvider',

	);

use Expstudio\FriendlyUrl\SluggableInterface;
use Expstudio\FriendlyUrl\SluggableTrait;

class Post extends Eloquent implements SluggableInterface
{

	use SluggableTrait;

	protected $sluggable = array(
		'build_from' => 'title',
		'save_to'    => 'slug',
	);

}

$post = new Post(array(
	'title' => 'My Awesome Blog Post'
));

$post->save();

echo $post->slug;

// or, if you don't know the name of the slug attribute:
echo $post->getSlug();

$new_post = $post->replicate()->resluggify();

return array(
	'build_from'      => null,
	'save_to'         => 'slug',
	'max_length'      => null,
	'method'          => null,
	'separator'       => '-',
	'unique'          => true,
	'

class Person extends Eloquent implements SluggableInterface {

	use SluggableTrait;

	public static $sluggable = array(
		'build_from' => 'fullname'
	);

	public function getFullnameAttribute() {
		return $this->firstname . ' ' . $this->lastname;
	}

}

Schema::create('posts', function($table)
{
	$table->increments('id');
	$table->string('title');
	$table->string('body');
	$table->string('slug');
	$table->timestamps();
});

		'method' => array('Illuminate\\Support\\Str', 'slug'),
	

		'method' => function( $string, $separator ) {
			return strtolower( preg_replace('/[^a-z]+/i', $separator, $string) );
		},
	

php artisan sluggable:table posts

php artisan sluggable:table posts slug_column