當我們使用 migrate 出現以下訊息:
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
這個問題出現在Laravel 5.4版本之後,調整方式如下
解決方式(一):
在 migrate 中使用 unique() 時指定長度為191,必須修改每一個有使用到 unique() 的migrate檔案
$table->string('email', 191)->unique();
解決方式(二):
編輯 app\Providers\AppServiceProvider.php 增加
use Schema;
並在boot funciton內增加
Schema::defaultStringLength(191);
完整程式碼如下:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
}
在Laravel 5.3版本起有了新的功能 循環變量 loop 使用foreach迴圈時可以在迴圈內使用$loop得到迴圈內的訊息
程式系統串接ChatGPT API共需要三組金鑰,分別為Organization ID、Project ID、API Key,詳細申請步驟。
PHP Laravel 取得客戶端IP的方式介紹
reCAPTCHA是目前針對防範機器人最為有效的方式,廣泛使用在各政府機關、民間網站的網頁設計中,此篇文章教學申請取得金鑰步驟。
get view html in controller laravel?如何在Controller中取得View Blade的HTML字串呢?