web.php
D/LogDebug: [P, o, k, é, m, o, n, , S, h, o, p]
D/LogDebug: getUTF8Length() = 12
(型号) 的 Chapter.php
Route::get('/books/{book}/chapter/{chapter}', [
'uses' =>'PostController@index'])->where(['book'=>'[-a-z0-9]+','chapter'=>'[0-9]+']);
我收到如下错误
章节模型如下所示。
Chapter.php
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Chapter extends Model
{
}
答案 0 :(得分:0)
您需要在模型中插入您的字段:
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Chapter extends Model
{
protected $table = 'chapter';
protected $fillable = ['id','book_id','title','preface','number','createdAt','updatedAt','createdBy','updatedBy','deletedBy'];
}
在模型中插入章节模型的所有字段。再试一次
答案 1 :(得分:0)
您使用错误的语法在$table
属性中定义字段。 $table
应该具有数据库表的名称!
此外,您可以设置质量分配可填写字段。
class Chapter extends Model
{
protected $table = 'chapter'; // database table name
protected $fillable = ['id','book_id','title','preface','number','createdAt','updatedAt','createdBy','updatedBy','deletedBy']; //
}
如果您想在模型中定义字段,可以使用$fields
(来自https://laracasts.com/discuss/channels/eloquent/model-definition的示例):
$fields = [
'firstName' => [
'cast' => 'string', // default, can be omitted
'maxlength' => 100,
'column' => 'first_name',
],
'lastName' => [
'cast' => 'string', // default, can be omitted
'maxlength' => 100,
'column' => 'last_name',
],
'isAdmin' => [
'cast' => 'boolean',
'column' => 'is_admin',
],
]