我希望使用POST从移动应用程序获取一些数据并将其保存在我的laravel 5应用程序数据库中。
myController的
public function postBookingDetails(Request $request)
{
$FodMaps = $request->only('name','fructose');
return $FodMaps;
}
Route::post('booking', 'FodMapController@postBookingDetails');
表格结构:
id(自动增量)
name varchar
模型
protected $table = 'food_directory';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'lactose', 'fructose','polyols','fructan'];
答案 0 :(得分:0)
public function postBookingDetails(Request $request)
{
$FodMaps = $request->only('name','fructose');
$FoodDirectory = new FoodDirectory;
$FoodDirectory->name = $request->input('name');
$FoodDirectory->fructose = $request->input('fructose');
$FoodDirectory->save();
return $FoodDirectory;
}
也会添加到您的模型中:
public $timestamps = false;
并且当然不要忘记添加到控制器的顶部:
use App\FoodDirectory;