vendredi 8 mai 2015

Use JSON Variable in Laravel to Update Table

I'm trying to send a JSON post request through ajax to Laraval to update a table. I'm receiving a 405 Method Not Allowed. I'm trying to use a variable to update that column in the table. I am using Laravel 4.2

My javascript code is...

var stylist = $("#stylist").val(); $.ajax({ type:"post", dataType: 'json', data: { firstName:firstName, lastName:lastName, phoneNumber:phoneNumber, date:date, timeslot: timeslot, stylist: stylist } });

My larval code is...

` if(Request::ajax()){

$firstName = Input::get('firstName');
$lastName = Input::get('lastName');
$phoneNumber = Input::get('phoneNumber');
$date = Input::get('date');
$time = Input::get('timeslot');
$stylist = Input::get('stylist');

$checkClient = DB::table('users')->where('firstName','=',$firstName)->where('lastName','=',$lastName)->where('phoneNumber','=',$phoneNumber)->pluck('id');

if($checkClient){
        $setBooking = DB::table('calendar')->where('dt','=',$date)->where('timeslot','=',$time)
                             ->update(array($stylist=>1,'clientID'=>$checkClient));
}
else {
        $enterNewClientId = DB::table('users')->insertGetId(array('firstName'=>$firstName, 'lastName'=>$lastName, 'phoneNumber'=>$phoneNumber,'role'=>0));
        $setNewBooking = DB::table('calendar')->where('dt','=',$date)->where('timeslot','=',$time)
                             ->update(array($stylist=>1,'clientID'=>$enterNewClientId));
}
}

I believe my problem is possibly using the variable in the update array.

Aucun commentaire:

Enregistrer un commentaire