balping / laravel-hashslug Goto Github PK
View Code? Open in Web Editor NEWPackage providing a trait to use Hashids on a model
License: GNU General Public License v3.0
Package providing a trait to use Hashids on a model
License: GNU General Public License v3.0
I can't get version 1.0.3, cause in one of last commits this branch starts requires illuminate/database 5.5.* . It is possible to get version 1.0.3 with latest bug fixes (invalid slug) or this package don't support laravel 5.4 anymore?
- balping/laravel-hashslug 1.0.3 requires illuminate/database 5.5.* -> satisfiable by illuminate/database[5.5.x-dev] but these conflict with your requirements or minimum-stability
I have a second question. I'm building API based on Laravel and I would like to return objects with hashed slug
instead id
. How can I do it?
data : {
id: 'H4sh3dSlu9',
email: '[email protected]',
created_at: '...',
updated_at: '...',
}
Hey,
It would be super awesome to disable the package in development. If I would have an option in the config with "enabled" or so I can debug much better. I don't know a quick hack for this because you can not include traits dynamically in PHP. Is there an exact code line where a quick and dirty "return" disables the whole package?
I added use HasHashSlug;
to my Task
model. I can see hashids being generated fine in urls, however when I go to edit page of the model, it gives error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'hashslug' in 'where clause' (SQL: select * from `tasks` where `hashslug` = Eby7m limit 1)
I am using implicit model binding.
Can you please tell what I am missing here other than adding use HasHashSlug;
to my model ?
The current implementation uses:
/**
* Used in implicit model binding AND
* used in explicit model binding if no callback
* is specified, eg: Route::model('post', Post::class)
*
* @param string $slug
* @return \Illuminate\Database\Eloquent\Model
*/
public function resolveRouteBinding($slug){
$id = static::decodeSlug($slug);
return parent::where($this->getKeyName(), $id)->first();
}
However, this results in a 404 error being thrown when we're attempting to view/restore a soft-deleted model. The following fixes this by adding withTrashed()
to the query:
/**
* Used in implicit model binding AND
* used in explicit model binding if no callback
* is specified, eg: Route::model('post', Post::class)
*
* @param string $slug
* @return \Illuminate\Database\Eloquent\Model
*/
public function resolveRouteBinding($slug){
$id = static::decodeSlug($slug);
return parent::withTrashed()->where($this->getKeyName(), $id)->first();
}
Hey,
Really cool package!
But I miss a custom accessor for the slug.
Look at this example: Model::all()->pluck('name', 'slug');
I won't work. Because slug is just a function. I modified your package and added
public function getHashidAttribute() {
return $this->slug();
}
With that I can simply Model::all()->pluck('name', 'hashid');
What do you think about it?
laravel-hashslug/src/HasHashSlug.php
Line 64 in 5b0f3ce
The env function will work at laravel debug environment but not work when laravel running at production.
Hey! Is it possible to set $minSlugLength
in config file? I want to use it in multiple models and don't want to define it each time.
For example:
return [
'appsalt' => 'your-application-salt',
'length' => 8,
'alphabet' => 'abcdefghijklmnopqrstuvwxyz',
];
Coudl you add this feature?
In some case, like below:
$query->whereSlug('user_id', $slug)->whereSlugIn('category_id',[$slug1, $slug2, $slug3]);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.