PHP code example of gorankrgovic / laravel-shortable

1. Go to this page and download the library: Download gorankrgovic/laravel-shortable 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/ */

    

gorankrgovic / laravel-shortable example snippets



use Gorankrgovic\LaravelShortable\Shortable;

class Video extends Model
{
    use Shortable;

    /**
     * Return the shortable configuration array for this model.
     *
     * @return array
     */
    public function shortable()
    {
        return [
            'short_url'
        ];
    }
}



$video = new Video([
    'whateve' => 'My Awesome Video',
]);

$video->save();


$video->short_url;

use Gorankrgovic\LaravelShortable\Services\ShortService;

$short = ShortService::createShort(Post::class, 'column_name');


Post::registerModelEvent('shorting', function($post) {
    if ($post->someCondition()) {
        // the model won't be shorted
        return false;
    }
});

Post::registerModelEvent('shorted', function($post) {
    Log::info('Post shorted: ' . $post->getShort());
});


$post = Post::whereShort($shortString)->get();

$post = Post::findByShort($shortString);

$post = Post::findByShortOrFail($shortString);

bash
php artisan vendor:publish --provider="Gorankrgovic\LaravelShortable\ServiceProvider"