Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 4bf9a3d

Browse files
committed
initial files
0 parents  commit 4bf9a3d

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor
2+
composer.lock
3+
.phpunit.result.cache

composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

src/Sluggable.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)