好吧,我一直在努力解决这个问题,因为我花了3个小时尝试不同的东西,而我根本无法让它工作,这是我的功能:
public function endshiftdata_post() {
Session::forget('success');
Session::forget('error');
$serial = Input::get('hidden_serial');
$game = Game::find($serial);
$shiftsgame = ShiftsGames::find($serial);
$sold = $game->tickets_sold();
$cash = Input::get('cash');
$unsold = Input::get('unsold');
$redeemed = Input::get('redeemed');
$input = Input::all();
$rules = array(
'cash' => 'required|numeric',
'unsold' => 'required|numeric',
'redeemed' => 'required|numeric',
);
$validation = Validator::make($input, $rules);
if ($shiftsgame->cash_out == 0) {
if ($validation->passes()) {
$shiftsgame->cash_out = $cash;
$game->tickets_unsold = $unsold;
$game->tickets_sold = $sold;
$shiftsgame->prizes_redeemed = $redeemed;
$game->prizes_redeemed = $redeemed;
$shiftsgame->end_time = Shifts::currentTime();
$game->end_shift_data = 1;
$game->save();
$shiftsgame->save();
Session::flash('success', "Successfully submitted data for " . $game->name . " (" . $game->serial . ")");
return Redirect::route('shift.index');
}
else {
Session::flash('error', "Make sure text boxes contain numbers only.");
return Redirect::route('shift.index');
}
}
}
如果我在datadump它显示的对象,这里是重要的信息: array(9){[" id"] => int(40)[" user_id"] => int(41)[" site_id"] => int(1)[" serial"] => string(8)" 6743591" [" START_TIME"] => string(19)" 2014-08-29 09:58:42" [" END_TIME"] => string(19)" 2014-08-29 09:59:39" [" cash_in"] => int(10)[" cash_out"] => int(500)[" prizes_redeemed"] => int(500)} [" original":protected] => array(9){[" id"] => int(40)[" user_id"] => int(41)[" site_id"] => int(1)[" serial"] => string(8)" 6743591" [" START_TIME"] => string(19)" 2014-08-29 09:58:42" [" END_TIME"] => string(19)" 2014-08-29 09:59:39" [" cash_in"] => int(10)[" cash_out"] => int(500)[" prizes_redeemed"] => INT(500)
所以你可以看到两个人的cash_out是500.
但是,在我的数据库中,我总共有4行......
它确实包含0但显然这个datadump显示那些因为某些原因没有被包含,即使序列号是相同的,这是ShiftGames :: find($ serial)应该做的...
有没有人有任何想法发生了什么?我很困惑:(:( :(请帮助!)
好的,这是我的ShiftGames课程:
class ShiftsGames extends Eloquent {
protected $table = 'shiftsgames';
protected $primaryKey = 'serial';
/**
*
*
* The attributes excluded from the model's JSON form.
*
*
*
* @var array
*
*/
protected $hidden = array();
public $timestamps = false;
public function getStartTime() {
return $this->start;
}
public function getEndTime() {
return $this->end;
}
public static function currentTime() {
date_default_timezone_set('America/Chicago');
$now = new DateTime;
return $now->format('Y-m-d g:i:s');
}
public function scopeCurrent($query) {
$query->where('user_id', '=', Auth::user()->id);
$query->where('end_time', '=', null);
return $query;
}
public static function endShift() {
$query = Shifts::current()->first();
$query->end_time = Shifts::currentTime();
$query->save();
}
}
我做了什么修复它是切换受保护的$ primaryKey =' serial&#39 ;;保护$ primaryKey =' id';
我没有改变我的功能:
Session::forget('success');
Session::forget('error');
$serial = Input::get('hidden_serial');
$game = Game::find($serial);
$sold = $game->tickets_sold();
$cash = Input::get('cash');
$unsold = Input::get('unsold');
$redeemed = Input::get('redeemed');
$input = Input::all();
$rules = array(
'cash' => 'required|numeric',
'unsold' => 'required|numeric',
'redeemed' => 'required|numeric',
);
$validation = Validator::make($input, $rules);
foreach (ShiftsGames::get() as $shiftgame) {
if ($shiftgame->cash_out == 0 and $serial == $shiftgame->serial) {
if ($validation->passes()) {
$shiftgame->cash_out = $cash;
$game->tickets_unsold = $unsold;
$game->tickets_sold = $sold;
$shiftgame->prizes_redeemed = $redeemed;
$game->prizes_redeemed = $redeemed;
$shiftgame->end_time = Shifts::currentTime();
$game->end_shift_data = 1;
$game->save();
$shiftgame->save();
Session::flash('success', "Successfully submitted data for " . $game->name . " (" . $game->serial . ")");
return Redirect::route('shift.index');
}
else {
Session::flash('error', "Make sure text boxes contain numbers only.");
return Redirect::route('shift.index');
}
}
}
}
}
皮埃尔看起来像是一个可以接受的修复程序吗?或者你还看到我正在做的事情的问题吗?它似乎正在发挥作用。