Reputation: 956
Ok, so my issue is, my ajax call isn't updating correctly. It's the same as many functions as I have, it's just not updating the values. Although, I can run the query on it's own in mysql and it update ok. Function is below:
/*
* "elerts/quicksave" > Update elert from all screen
*/
public function quicksave($id)
{
$data = (object)Input::get();
$ev = Events::find($id);
$ev->limit = $data->limit;
$ev->EventEnabled = $data->EventEnabled;
$ev->SundayStart = $data->SundayStart;
$ev->MondayStart = $data->MondayStart;
$ev->TuesdayStart = $data->TuesdayStart;
$ev->WednesdayStart = $data->WednesdayStart;
$ev->ThursdayStart = $data->ThursdayStart;
$ev->FridayStart = $data->FridayStart;
$ev->SaturdayStart = $data->SaturdayStart;
$ev->save();
$queries = DB::getQueryLog();
$last_query = end($queries); dd($last_query);
return "Your eLert has been saved!";
}
Below is an example ID getting passed and an example of the $data object that's getting passed.
$id = '107';
object(stdClass)#137 (9) { ["limit"]=> string(3) "400" ["EventEnabled"]=> string(1) "1" ["SundayStart"]=> string(1) "0" ["MondayStart"]=> string(1) "0" ["TuesdayStart"]=> string(1) "0" ["WednesdayStart"]=> string(1) "0" ["ThursdayStart"]=> string(1) "1" ["FridayStart"]=> string(1) "1" ["SaturdayStart"]=> string(1) "1"}
I'm confused as to why nothing is getting updated. Any help?
EDIT: Below I've included the code for my model so people won't have to question it...
<?php
/**
* @author jmadrigal
* Date: 7/2/14
* Time: 10:23 AM
*/
class Events extends Eloquent {
protected $primaryKey = 'eventid';
public $timestamps = false;
protected $fillable = array(
'eventname', 'eventdescription', 'EventEnabled', 'visitcost', 'groupid', 'flagid', 'SundayStart', 'MondayStart', 'TuesdayStart', 'WednesdayStart', 'ThursdayStart', 'FridayStart',
'SaturdayStart', 'limit', 'Vtmpl', 'delayV', 'Etmpl', 'delayE', 'Ttmpl', 'delayT', 'Mtemp', 'delayM', 'Login', 'freqv', 'freqt', 'freqe', 'maxe', 'maxt', 'maxv',
'amtide', 'amtidt', 'amtidv', 'apptinterval'
);
public function aInterval() {
return $this->hasMany('AppointmentInterval');
}
}
Upvotes: 0
Views: 6651
Reputation: 956
The type being sent "string" for any checkbox wasn't going in because the values needed to be an (int) value or a (bool) value of '1' or '0'. That was the issue. Database was set up a year ago by someone else and I didn't catch that until now. It's fixed though.
Upvotes: 0
Reputation: 7152
More than likely you have not defined the mass-assignment attributes your Events
Model.
So in your Events
Model try:
protected $fillable = array('limit', 'EventEnabled', 'SundayStart', 'MondayStart', 'TuesdayStart', 'WednesdayStart', 'ThursdayStart', 'FridayStart', 'SaturdayStart');
This is a security feature of Laravel and helps to prevent against blindly allowing any attributes to be updated.
Upvotes: 5