2017-06-21 29 views
0

從來就通過工匠流明5.4.x版本錯誤的表名

public function up() 
{ 
    Schema::create('log', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->string('priority'); 
     $table->string('level'); 
     $table->string('content'); 
     $table->timestamps(); 
    }); 
} 

這完美地工作創造了一個表,表中現有的。

之後,我想通過api/v1/log上的GET請求進行API調用以獲取所有(不存在,我知道)entrys,這會導致HTTP 500錯誤。

在流明數(storage/logs/lumen.log)我可以找到以下內容:

[2017-06-21 10:20:28] lumen.ERROR: PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'serviceAPI.logs' doesn't exist in [...]

誰能告訴我,爲什麼API改掉打開logs,而不是log

UPDATE:日誌模型

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Log extends Model 
{ 
protected $fillable = ['priority', 'level', 'content']; 
} 
?> 

回答

1

數據庫表名需要被改變的log代替logs

您可以從日誌模型

protected $table = 'log'; 
protected $primaryKey = 'id'; 
+0

作爲表名更改在我迄今爲止看到的alle教程中描述的模型中沒有定義名稱,所以我不能更改/ rena我在模型中關於表名稱的任何事情(我在OP中添加了模型)。 – Michael

+0

您是否試過這樣的 class Log extends Model protected $ table ='log'; protected $ fillable = ['priority','level','content']; } ?> – Hari

+0

這確實奏效。在這一點上,我的問題仍然是「爲什麼流明使用'日誌'之前,如果它沒有配置在任何地方?」 – Michael