【发布时间】:2016-03-05 11:21:15
【问题描述】:
我刚开始使用 laravel,但我在这部分上有所保留,其中我无法使用 PostgreSQl 成功地将用户输入的数据保存在数据库中,因为它只显示除 id 及其时间戳之外的空白条目。为什么使用 Laravel 在我的数据库字段中插入空白数据?这是我的代码:
Javascript
<script type="text/javascript">
$(".submit-prod").click(function(e){
e.preventDefault();
$.post("{{ url('/addprod') }}",$("#prod-form").serialize(),function(data) {
if(data.notify == "Success"){
console.log(data.notify);
}
},"json");
}); //end
Route.php
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/', function () {
return view('welcome');
});
Route::any('addprod', 'Product\ProductController@store');
Route::get('/home', 'HomeController@index');
});
ProductController.php
<?php
namespace App\Http\Controllers\Product;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Product\Product as Product;
class ProductController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('home');
}
public function store(Request $request){
$products = Product::create($request->all());
if($products){
$notification = "Success";
} else{
$notification = "Failed";
}
return json_encode(array('notify'=>$notification));
}
}
模型(Product.php)
<?php
namespace App\Product;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
//
}
输出(空白字段)
【问题讨论】:
-
请帮帮我。请提供任何帮助。
标签: php ajax postgresql laravel laravel-5.2