laravel 中 1364 Field 'repost_id' doesn't have a default value

1.阻止默认响应:preventDefault() 方法阻止元素发生默认的行为(例如,当点击提交按钮时阻止对表单的提交)。http://www.w3school.com.cn/jquery/event_preventdefault.asp

2.通过js直接到达控制器,而不用通过提交和action : http://api.jquery.com/jQuery.post/

3.

 

错误原因:1. laravel5.5 中链接数据库时,使用模板对数据库进行关联,多对多操作;一般情况下此模板与数据库名相似,根据上图可以看到数据库名为 statuses,所以模板所在位置 app\models\Status;(模板为单数)如图所示:。打开文件,找到 $fillable,这里是允许对数据库操作的字段,此处明显没有错误中指出的字段,所以将此处更改为(注意,将这里更改为自己数据表中字段)。

4.

 错误原因:连续两个创建,造成涌余,所导致错误:(

 Status::create就是参入数据的意思;
$status->create()也是参入数据的意思;
但是第一个参入后第二个就没有数据,所以导致这种错误。

$status = Status::create([
            'repost_id' => (int)$request->report_id,
            'content' => $request->report_text,
            'repost_count'=>1,
            'user_id' =>(int)Auth::user()->id,
        ]);
        $request->repost_count+1;
//        dd(count($status->repost_count));
//   $status->create();
//使用下面这条语句可以在创建新数据时,同时对原数据进行更改:
use DB;
DB::table('repost_count') ->where('id', $request->report_id) ->update(['字段名字' => 想给字段赋予的值]);

  

 

posted on 2017-12-25 17:56  盧鵬  阅读(982)  评论(0编辑  收藏  举报