diff --git a/app/Category.php b/app/Category.php
index 8bef171..4631ec9 100755
--- a/app/Category.php
+++ b/app/Category.php
@@ -9,6 +9,7 @@
*
* @property int $id
* @property string $name
+ * @property string $slug
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property-read string $detail
@@ -23,18 +24,9 @@ class Category extends Model
*/
protected $fillable = [
'name',
+ 'slug'
];
- /**
- * Get the category name.
- *
- * @return string
- */
- public function getDetailAttribute()
- {
- return ucfirst($this->name);
- }
-
/**
* Get the category posts.
*
diff --git a/app/Console/Commands/Install.php b/app/Console/Commands/Install.php
index 44f3df4..9ff5500 100755
--- a/app/Console/Commands/Install.php
+++ b/app/Console/Commands/Install.php
@@ -89,7 +89,10 @@ protected function createCategories()
$categories = $this->category->listName();
foreach (config('system.default_category') as $key => $value) {
if (!in_array($value, $categories)) {
- Category::create(['name' => $value]);
+ Category::create([
+ 'name' => $value,
+ 'slug' => str_slug($value),
+ ]);
}
}
}
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index 8d7e171..af40892 100755
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -68,10 +68,13 @@ public function index()
*/
public function store(CategoryRequest $request)
{
- if (Category::whereName(str_slug(request('name')))->exists()) {
+ if (Category::where('slug', str_slug(request('name')))->exists()) {
return $this->error(['message' => trans('category.exists')]);
}
- $category = Category::create(['name' => str_slug(request('name'))]);
+ $category = Category::create([
+ 'name' => request('name'),
+ 'slug' => str_slug(request('name')),
+ ]);
$this->activity->record([
'module' => $this->module,
diff --git a/app/Repositories/PostRepository.php b/app/Repositories/PostRepository.php
index 3886ef6..2e24595 100755
--- a/app/Repositories/PostRepository.php
+++ b/app/Repositories/PostRepository.php
@@ -109,7 +109,7 @@ public function getBySlug($slug)
*/
public function getByCategoryAndSlug($category, $slug)
{
- $category = Category::where('name', $category)->first();
+ $category = Category::where('slug', $category)->first();
if (!$category) {
return null;
diff --git a/config/system.php b/config/system.php
index 57e27a3..589bafc 100755
--- a/config/system.php
+++ b/config/system.php
@@ -24,7 +24,7 @@
"user" => "user",
],
"default_category" => [
- "articles" => "articles",
+ "articles" => "Articles",
],
"public_config" => [
"color_theme",
diff --git a/database/migrations/2018_08_04_202444_add_slug_column_to_categories_table.php b/database/migrations/2018_08_04_202444_add_slug_column_to_categories_table.php
new file mode 100644
index 0000000..1a0c046
--- /dev/null
+++ b/database/migrations/2018_08_04_202444_add_slug_column_to_categories_table.php
@@ -0,0 +1,32 @@
+string('slug')->nullable()->after('name');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('categories', function (Blueprint $table) {
+ $table->dropColumn('slug');
+ });
+ }
+}
diff --git a/resources/assets/js/routes.js b/resources/assets/js/routes.js
index 228546c..9074d6b 100755
--- a/resources/assets/js/routes.js
+++ b/resources/assets/js/routes.js
@@ -215,7 +215,7 @@ let routes = [
{
path: '/:category/:slug',
component: require('./views/post/View.vue'),
- meta: {title: appName + ' | ' + i18n.post.view}
+ meta: {title: appName}
},
{
path: '*',
diff --git a/resources/assets/js/views/category/Category.vue b/resources/assets/js/views/category/Category.vue
index 3f9ea17..9b5fe92 100755
--- a/resources/assets/js/views/category/Category.vue
+++ b/resources/assets/js/views/category/Category.vue
@@ -36,12 +36,14 @@
{{ trans('category.name') }}
+ {{ trans('category.slug') }}
Action