PHP code example of pacificinternet / laravel-hashslug

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

    

pacificinternet / laravel-hashslug example snippets



use Illuminate\Database\Eloquent\Model;
use Balping\HashSlug\HasHashSlug;

class Post extends Model {
    use HasHashSlug;
}

// routes/web.php
Route::resource('/posts', 'PostController');

// somewhere else
$post = Post::first();
echo action('PostController@show', $post);
// prints http://localhost/posts/K4Nkd

// app/Http/Controllers/PostController.php

public function show($slug){
    $post = Post:findBySlugOrFail($slug);
  
    return view('post.show', compact('post'));
}

// routes/web.php
Route::resource('/posts', 'PostController');

// app/Http/Controllers/PostController.php
public function show(Post $post){
    return view('post.show', compact('post'));
}

//app/Providers/RouteServiceProvider.php
public function boot(){
    parent::boot();

    Route::model('article', App\Post::class);
}

// routes/web.php
Route::resource('/articles', 'PostController');

// app/Http/Controllers/PostController.php
public function show(Post $post){
    return view('post.show', compact('post'));
}



return [
    'appsalt' => 'your-application-salt'
];

class Post extends Model {
    use HasHashSlug;

    protected static $modelSalt = "posts";
}

class Post extends Model {
    use HasHashSlug;

    protected static $minSlugLength = 10;
}

    'minSlugLength' => 10

class Post extends Model {
    use HasHashSlug;

    protected static $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
}

    'alphabet' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

class Post extends Model {
    use HasHashSlug;

    protected static $hashSlugPrefix = 'post-';
}