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.

Scala key/value case class to Json

Given the following case class:

case class ValueItem(key: String, value: String)

and the following json formatter:

implicit val valueItemFormat: Format[ValueItem] = (
        (__ \ "key").format[String] and
        (__ \ "value").format[String])(ValueItem.apply, unlift(ValueItem.unapply))

a json representation of a ValueItem instance like

ValueItem("fieldname", "fieldValue")

is

{ "key" : "fieldName" , "value" : "fieldValue" }

I'm wondering how to get a json in a flat key/value serialization like

{ "fieldName" : "fieldValue" }

Error while converting Oracle results to JSON

I'm getting this error while retrieving data from an Oracle database table using a PHP web service: It shows the warning - unsupported json

Warning: [json] (json_encode_r) type is unsupported, encoded as null.

This is my code:

<?php 
    require_once("Classes/abc.php");
    $h=new NetworkLevel();
    $rs=$h->GetWEBSERVICE_STATS();
    //$h->Display($rs); -- commented

    echo json_encode($rs);

?> 

This is my NetworkLevel Class Code:

<?php 
require_once('connect.php'); 
class NetworkLevel 
{    
    public $fdate; 
    public $tdate; 
    public function Display($recordset)
    { 
        rs2html($recordset); 
    } 


    function GetWEBSERVICE_STATS()
    { 
        $xCon=Connect(); 
        $xCon->SetFetchMode(ADODB_FETCH_ASSOC); 
        $str="Select * from DEPT"; 
        $recordset= $xCon->Execute($str); 
        return $recordset; 
    }    

    catch (exception $e) 
    { 
        var_dump($e); 
    } 
    return $recordset; 

    }    

} 

?>