我尝试将数据插入数据。
public function up()
{
Schema::create('request_song', function (Blueprint $table) {
$table->increments('id');
$table->string('song_name', 150);
$table->string('singer_name', 50);
$table->string('general_input', 200);
$table->timestamps();
});
}
RequestSongModel
class RequestSongModel extends Model
{
protected $table = 'request_song';
protected $fillable = [
'id',
'song_name',
'singer_name'
];
}
控制器
public function store(Request $request)
{
$rule = [
'song_name' => 'required',
'singer_name' => 'required',
];
$this->validate($request, $rule);
$requestSong = RequestSongModel::created($request->all());
return response()->json(['DATA' => $requestSong], 201);
}
当我插入时,它响应为null。
{ “DATA”:null}
我不知道,为什么它响应为null。 请帮帮我
答案 0 :(得分:1)
这个怎么样
$requestSong = RequestSongModel::created($request->all());
到
$requestSong = RequestSongModel::create($request->all());