web.php
Route::get('/books/{book}/chapter/{chapter}', [
'uses' =>'PostController@index'])->where(['book'=>'[-a-z0-9]+','chapter'=>'[0-9]+']);
(Model) Chapter.php
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Chapter extends Model
{
}
I am getting error like below
Chapter Model is like below.
Chapter.php
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Chapter extends Model
{
protected $table = 'id','book_id','title','preface','number','createdAt','updatedAt','createdBy','updatedBy','deletedBy';
}
You need insert your fields inside your model:
<?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'];
}
Insert all fields of chapter model inside your model. And try again
You define your fields in the $table
property with a wrong syntax. $table
should have the name of your database table! Additionally, you can set your mass assignment fillable fields.
class Chapter extends Model
{
protected $table = 'chapter'; // database table name
protected $fillable = ['id','book_id','title','preface','number','createdAt','updatedAt','createdBy','updatedBy','deletedBy']; //
}
If you want to define your fields in your model, you can use the $fields
(example from 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',
],
]