1. Go to this page and download the library: Download taylornetwork/model-slugger 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/ */
taylornetwork / model-slugger example snippets
// app/ExampleModel.php
namespace App;
use Illuminate\Database\Eloquent\Model;
use TaylorNetwork\ModelSlugger\ModelSlugger;
class ExampleModel extends Model
{
use ModelSlugger;
public function sluggerConfig()
{
return [
'source' => 'name',
];
}
}
protected $sluggerRouteModelBind = true;
// app/ExampleModel.php
public function sluggerConfig()
{
return [
'source' => 'name',
'unique' => 'all',
];
}
// app/TodoList.php
public function sluggerConfig()
{
return [
'source' => 'name',
'unique' => 'parent',
'parent' => 'App\User',
];
}
public function boot()
{
Route::bind('user', function ($value) {
return App\User::findOrFail($value); // Code to find by ID or slug
});
Route::bind('todoList', function ($slug, $route) {
// $route->parameter('user') will return an instance of App\User
return $route->parameter('user')->todoLists()->where('slug', $slug)->firstOrFail();
});
parent::boot();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.