1. Go to this page and download the library: Download eriksulymosi/eloquent-sqids 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/ */
eriksulymosi / eloquent-sqids example snippets
use Illuminate\Database\Eloquent\Model;
use ErikSulymosi\EloquentSqids\HasSqid;
use ErikSulymosi\EloquentSqids\SqidRouting;
Class Item extends Model
{
use HasSqid, SqidRouting;
}
// Generating the model sqid based on its key
$item->sqid();
// Equivalent to the above but with the attribute style
$item->sqid;
// Finding a model based on the provided sqid or
// returning null on failure
Item::findBySqid($sqid);
// Finding a model based on the provided sqid or
// throwing a ModelNotFoundException on failure
Item::findBySqidOrFail($sqid);
// Decoding a sqid to its equivalent id
$item->sqidToId($sqid);
// Encoding an id to its equivalent sqid
$item->idToSqid($id);
// Getting the name of the sqid connection
$item->getSqidsConnection();
use Illuminate\Database\Eloquent\Model;
use ErikSulymosi\EloquentSqids\HasSqid;
class Item extends Model
{
use HasSqid;
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['sqid'];
}
use Illuminate\Database\Eloquent\Model;
use ErikSulymosi\EloquentSqids\HasSqid;
use ErikSulymosi\EloquentSqids\SqidRouting;
class Item extends Model
{
use HasSqid, SqidRouting;
}
Route::get('/items/{item:slug}', function (Item $item) {
return $item;
});
use Illuminate\Database\Eloquent\Model;
use ErikSulymosi\EloquentSqids\HasSqid;
use ErikSulymosi\EloquentSqids\SqidRouting;
class Item extends Model
{
use HasSqid, SqidRouting;
public function getRouteKeyName()
{
return 'slug';
}
public function getRouteKey()
{
return $this->slug;
}
}
Route::get('/items/{item:sqid}', function (Item $item) {
return $item;
});
Route::get('/items/{item}', function (Item $item) {
return $item;
})->withTrashed();
Route::get('/user/{user}/items/{item}', function (User $user, Item $item) {
return $item;
})->scopeBindings();
sh
$ php artisan vendor:publish
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.