Laravel 4.2 save()方法在异常处理程序中抛出"错误。"

时间:2016-04-28 13:06:12

标签: php ubuntu laravel-4

我对Laravel来说有点新鲜。我正在尝试将FORM数据插入到我的表中。 save()方法抛出上面提到的异常。以下是详细信息。 有人可以帮助找到问题,谢谢! 我正在使用UBUNTU 14.04 OS

路线:



Route::get('/', 'HomeController@showHomePage');
Route::post('saveClientData', 'DataController@storeData');




型号:



class client extends Eloquent{
    
    protected $table = 'client';
    
}




控制器:



<?php

class DataController extends BaseController {

/**
 * Stores client data. 
 * 
 */    

public function storeData()
{
        $client = new client();
        $client->clientName = Input::get('clientName');
        $client->clientLocation = Input::get('clientLocation');
        $client->clientBid = Input::get('clientBid');
        
        $client->save();
//            echo 'passed2';
}

}
&#13;
&#13;
&#13;

FORM:

&#13;
&#13;
<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Laravel PHP Framework</title>
        <link rel="stylesheet" href="/css/styles.css" />
    </head>
    <body>
        <div class="header">
            <h1 id="header-logo">clients.com</h1>
        </div>
        <div class="mypage-form">
            {{ Form::open(array('url' => 'saveClientData')) }}
                <div class="row col-xs-12"><h2>Registration</h2></div>
                <div class="row valid1">
                    <div class="col-xs-12">{{ Form::label('client-name', 'Client Name') }}</div>
                    <div class="col-xs-12 inputstyle">
                        {{ Form::text('clientName') }}
                    </div>
                    <div class="col-xs-12"><span class="error1"></span></div>
                </div> 
                <div class="row valid1">
                    <div class="col-xs-12">{{ Form::label('client-location', 'Client Location') }}</div>
                    <div class="col-xs-12 inputstyle">
                        {{ Form::text('clientLocation') }}
                    </div>
                    <div class="col-xs-12"><span class="error1"></span></div>
                </div>
                <div class="row valid1">
                    <div class="col-xs-12">{{ Form::label('client-bid', 'Client Bid') }}</div>
                    <div class="col-xs-12 inputstyle">
                        {{ Form::text('clientBid') }}
                    </div>
                    <div class="col-xs-12"><span class="error1"></span></div>
                </div>
                <div class="row valid1">
                    <div class="col-xs-12"><a href="getClientData">Clients List</a></div>
                </div>
                <div class="row">
                    <div class="col-xs-12 buttonstyle" id="clientReg">
                        {{ Form::submit('Save') }}
                    </div>
                </div>
                <div class="row">
                    &nbsp;
                </div>    
            {{ Form::close() }}
        </div>
        <div class="footer">
            <h4>Footer@clients.com</h4>      
        </div>
    </body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

我能够自己解决这个问题。添加主键和时间戳覆盖后,问题得到解决。

class client extends Eloquent{
    
    protected $table = 'client';
    protected $primaryKey = 'clientName';
    public    $timestamps = false;
    
}