This repository was archived by the owner on Feb 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ vendor
2
+ composer.lock
3
+ .phpunit.result.cache
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " codinglabsau/laravel-sluggable" ,
3
+ "description" : " Generate slugs when saving Eloquent models" ,
4
+ "keywords" : [
5
+ " Coding Labs" ,
6
+ " laravel-sluggable"
7
+ ],
8
+ "homepage" : " https://github.com/codinglabsau/laravel-sluggable" ,
9
+ "license" : " MIT" ,
10
+ "authors" : [
11
+ {
12
+ "name" : " Steve Thomas" ,
13
+ "email" : " steve@codinglabs.com.au" ,
14
+ "homepage" : " https://codinglabs.com.au"
15
+ }
16
+ ],
17
+ "require" : {
18
+ "php" : " ^7.2.5" ,
19
+ "illuminate/support" : " ^6.0|^7.0|^8.0"
20
+ },
21
+ "autoload" : {
22
+ "psr-4" : {
23
+ "Codinglabs\\ Sluggable\\ " : " src"
24
+ }
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Codinglabs \Sluggable ;
4
+
5
+ use Illuminate \Support \Str ;
6
+
7
+ trait Sluggable
8
+ {
9
+ public static function findBySlug (string $ slug ): self
10
+ {
11
+ return self ::where ('slug ' , strtolower ($ slug ))->first ();
12
+ }
13
+
14
+ public function setNameAttribute (string $ value ): void
15
+ {
16
+ $ this ->attributes ['name ' ] = $ value ;
17
+ $ this ->attributes ['slug ' ] = Str::slug ($ value );
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments