iT邦幫忙

0

設計規劃--資料表中 slug 這屬性 有何用?

有請大大解釋疑惑:
以下資料表設計中的 slug 用途是甚麼?
網路文章多表示:查詢資料時可以使用id,但是id 比較適合電腦判讀 不利人類閱讀,因此設置 slug 方便人類查詢...並且有利於 seo,問題是現在不都是 滑鼠按一按 、 手指點一點 就開啟自己想看的資料嗎? 有誰會輸入 slug 打開資料,就是要輸入資料 應該也適用於查詢不是嗎?

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Create table for storing roles
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('author_id');
            $table->integer('category_id')->nullable();
            $table->string('title');
            $table->string('seo_title')->nullable();
            $table->text('excerpt');
            $table->text('body');
            $table->string('image')->nullable();
            
            //這個 slug 用途?
            $table->string('slug')->unique();
            
            $table->text('meta_description');
            $table->text('meta_keywords');
            $table->enum('status', ['PUBLISHED', 'DRAFT', 'PENDING'])->default('DRAFT');
            $table->boolean('featured')->default(0);
            $table->timestamps();

            //$table->foreign('author_id')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('posts');
    }
}

看更多先前的討論...收起先前的討論...
Victor iT邦新手 2 級 ‧ 2020-04-23 14:54:50 檢舉
據我目前的了解SEO有加分,另外用這個可能不想被爬蟲機器人照順序爬走資料
感謝!
請問這意思是說 以 slug 取代 id ? (=不使用id ?)
Victor iT邦新手 2 級 ‧ 2020-04-23 15:37:26 檢舉
資料庫我認為一樣保留ID 做關聯應用,使用者 網址上使用 slug 替代 給使用者看的 唯一值,用於SEO加分外也增加爬蟲難度,或不想讓別人知道資料庫有多少筆資料,資料庫照理來說會保留ID。

如下遞增的ID,可以寫爬蟲一個一個抓,比較方便

https://localhost/posts/1
https://localhost/posts/2
...


如果slug 或 亂數ID 像 youtube
https://www.youtube.com/watch?v=aJOTlE1K90k

可以增加爬蟲難度吧! 小弟的觀點,有誤請各位厲害的大大指教。
有道哩!能增加安全性
有些網路文章說:有利於用戶閱讀
在這層面上 真有意義嗎?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答