php - Laravel 5.1 create not working -


i new laravel 5.1. i'm watching tutorial video , in video teacher using code insert data in database :

<?php  namespace app\http\controllers;  use app\comments; use illuminate\http\request; use app\http\requests; use app\http\controllers\controller;  class commentcontroller  extends controller {     public function getcommentnew()     {         $data = array(              'commenter' => 'soheil' ,             'comment  ' => 'test content' ,             'email'     => 'soheil@gmail.com' ,             'post_id'   =>  1 ,         ) ;         comments::create( $data );     }   } 

i doing steps him have problem , fields ecept created_at , updated_at empty :

enter image description here

this comments model :

<?php namespace app; use illuminate\database\eloquent\model; class comments extends model {     protected $fillable = ['commenter,email,post_id,comment,approved'];     public function post(){         return $this->belongsto('app\posts');     } } 

and migration :

<?php use illuminate\database\schema\blueprint; use illuminate\database\migrations\migration;  class createcommentstable extends migration {     public function up()     {         schema::create('comments', function (blueprint $table) {             $table->increments('id');             $table->unsignedinteger('post_id');             $table->string('commenter') ;             $table->string('email') ;             $table->text('comment') ;             $table->boolean('approved');             $table->timestamps();         });     }      public function down()     {         schema::drop('comments');     } } 

you haven't set $fillable attribute in model, try :

// in model protected $fillable = [     'commenter','email','post_id','comment','approved' ]; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -