0
我尝试向数据插入数据。Laravel5.4 - 如何使用POST方法将数据插入数据库
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);
}
当我插入,它响应空。
{ “DATA”:空}
我不知道,为什么它响应空。 请帮我
喔,怎么谢谢主席先生 – Vichit
澄清:'created'是洋洋洒洒的ORM而引发的事件'创造'实际上创造了模型。 – milo526