Laravel 5.3 - Missing "value" attribute in query builder - datatables

I am new to Laravel and Yajra datatable. I have developed a web application (In windows XAMPP) and everything works perfectly until I upload my project in shared hosting (UNIX) recently, the datatable unable to load the view and throwing the error message.
The error message I get is:
ErrorException in Request.php line 38:
Undefined index: value
in Request.php line 38
at HandleExceptions->handleError('8', 'Undefined index: value', '/home/posgb/public_html/boatMain/vendor/yajra/laravel-datatables-oracle/src/Request.php', '38', array()) in Request.php line 38
I have compared DD results of my query builder output in both my machine and server and found that the "value" attribute was missing from the "search" array.
My query:
$query = DB::table('item_subcat')
->leftJoin('item_customized', 'item_subcat.subcatID', '=', 'item_customized.subcatID')
->join('item_cat', 'item_subcat.itemCatID', '=', 'item_cat.itemCatID')
->select(array('item_subcat.subcatID', 'item_subcat.itemCode', 'item_subcat.itemName', 'item_cat.itemCatName', 'item_customized.customize_name', DB::raw('IF(item_subcat.is_categorize = "0", item_subcat.itemPrice, item_customized.price) AS ITEMPRICE'), 'item_subcat.is_activate', 'item_customized.itemCustomID'));
dd($query);
DD results in my pc:
#parameters: array:7 [
"draw" => "1"
"columns" => array:7 [
0 => array:5 [ …5]
1 => array:5 [ …5]
2 => array:5 [ …5]
3 => array:5 [ …5]
4 => array:5 [ …5]
5 => array:5 [ …5]
6 => array:5 [ …5]
]
"order" => array:1 [
0 => array:2 [ …2]
]
"start" => "0"
"length" => "10"
"search" => array:2 [
"value" => "" /*This is the missing value */
"regex" => "false"
]
"branch" => "ALL"
]
}
DD result in my server:
+request: ParameterBag {#41
#parameters: array:7 [
"draw" => "1"
"columns" => array:7 [
0 => array:5 [ …5]
1 => array:5 [ …5]
2 => array:5 [ …5]
3 => array:5 [ …5]
4 => array:5 [ …5]
5 => array:5 [ …5]
6 => array:5 [ …5]
]
"order" => array:1 [
0 => array:2 [ …2]
]
"start" => "0"
"length" => "10"
"search" => array:1 [
"regex" => "false"
]
"branch" => "ALL"
]
}
Please can advise me where should I look into the missing "value" in array, as it cause me unable to generate the datatable. TYVM for those spent times to look at this.

The reason was due to PHP.ini settings in my server which disallow null value in GET and POST request by default.

Related

Convert Array Into String Array

array:5 [
0 => array:1 [
"location_id" => 1
]
1 => array:1 [
"location_id" => 4
]
2 => array:1 [
"location_id" => 6
]
3 => array:1 [
"location_id" => 7
]
4 => array:1 [
"location_id" => 8
]
]
convert this into ["1","4","6","7","8",]
as used this ["1","4","6","7","8",]array in different query
You can use Laravel Collection pluck method to only return property which you want from each array item, and after that flatten the result array with flatten
$data = [
[
"location_id" => 1
],
[
"location_id" => 4
],
[
"location_id" => 6
],
[
"location_id" => 7
],
[
"location_id" => 8
]
];
$result = collect($data)->pluck('location_id')->flatten();
You can use the laravel helper array flatten method: Read more about it from here: https://laravel.com/docs/9.x/helpers#method-array-flatten
// Add the helper class call in the controller header
use Illuminate\Support\Arr;
// The actual array
$array = [
0 => [
"location_id" => 1
],
1 => [
"location_id" => 4
],
2 => [
"location_id" => 6
],
3 => [
"location_id" => 7
],
4 => [
"location_id" => 8
]
];
// Flatten the array function
$result = Arr::flatten($array);
Results:
['1','4','6','7','8']
Not as clean you might want but get the job done:
$resultSet = collect($data)->map(function($item){
return $item['location_id'];
})->toArray();
$resultString = "[";
foreach($resultSet as $item){
$resultString .= "'{$item}'" . ",";
}
$resultString = rtrim($resultString, ","); // produces this: "['1','4','6','7','8']"
$resultString .= "]";
dd($resultString);
You can use the laravel helper array pluck method Read more about it from here: https://laravel.com/docs/9.x/helpers#method-array-pluck
$array = [
0 => [
"location_id" => 1
],
1 => [
"location_id" => 4
],
2 => [
"location_id" => 6
],
3 => [
"location_id" => 7
],
4 => [
"location_id" => 8
]
];
$data = \Arr::pluck($array, 'location_id'); // [1,4,6,7,8]
$result = array_map('strrev', $data);
Result
["1","4","6","7","8"]

get one Array from Arrays

in controller I have array $checked
array:4 [▼
0 => "3"
1 => "4"
2 => "5"
3 => "8"
]
from base I want get second array, like this, but cannot:
$proservices = Proservice::whereIn('service_id', $checked)->get('product_id')->toArray();
it gives me 2 arrays:
array:3 [▼
0 => array:1 [▼
"product_id" => 14
]
1 => array:1 [▼
"product_id" => 7
]
2 => array:1 [▼
"product_id" => 14
]
]
help me to get array like this:
array:2 [▼
0 => "14"
1 => "7"
]

Drupal create node by post Api call fail with message "Could not determine entity type bundle: \\u0022type\\u0022 field is missing."}

I'm trying to create a node via drupal API but I have this error:
Got error 'PHP message: PHP Fatal error: Uncaught GuzzleHttp\\Exception\\ClientException: Client error: `POST https://site.it/entity/node?_format=hal_json` resulted in a `422 Unprocessable Entity` response:\n{"message":"Could not determine entity type bundle: \\u0022type\\u0022 field is missing."}
this is my function:
public function createFaq($notes, $telegram_id){
$url = "/entity/node?_format=hal_json";
$opt = [
'headers' => self::$baseHeader,
'body' => json_encode([
[
'type' => [ ['target_id' => 'faq'] ],
'title' => 'title',
'utente' => [ [ 'target_id' => '123462' ] ],
'field_domanda' => [ [ 'value' => $notes['domanda'] ] ],
'field_presenza' => [ [ 'value' => $notes['presenza'] == "Si"? true : false ] ],
]
])
];
$response = $this->client->request('POST', $url , $opt);
$r = json_decode( $response->getBody());
return $r;
}
But i't really strange because this other function is working
public static function createUser($title){
$url= "/entity/node?_format=hal_json";
$opt = [
'headers' => self::$baseHeader,
'body' => json_encode([
'title' => [ [ 'value' => $title ] ],
'type' => [ [ 'target_id' => 'article' ] ],
])
];
$response = $this->client->request('POST', $url , $opt);
$r = json_decode( $response->getBody());
return $r;
}
Can someone understood my error?
This is because the json data are enclosed in square brackets twice, just remove one pair :
$opt = [
'headers' => self::$baseHeader,
'body' => json_encode([
//[
'type' => [ ['target_id' => 'faq'] ],
'title' => 'title',
'utente' => [ [ 'target_id' => '123462' ] ],
'field_domanda' => [ [ 'value' => $notes['domanda'] ] ],
'field_presenza' => [ [ 'value' => $notes['presenza'] == "Si"? true : false ] ],
//]
])
];

Yii1 single login in mutlilingual site ( two domaines)

I got two domains for a mutlilingual site :www.monsite.fr and www.mysite.com
they use the same app and same databas.
i made a htaccess redirection.
But when you log yourself in the www.monsite.fr you aren't logged in www.mysite.com .
How can i do to make the session cookie valid for both ?
You need to create separate domain just for your cookies i.e.:
cookie.monsite.com
Then you need to set proper cookie domain in your configuration (Yii 2 example):
// ...
'components' => [
// ...
'user' => [
// ...
'identityCookie' => [
'name' => '_identity',
'httpOnly' => true,
'domain' => 'cookie.monsite.com',
],
],
'session' => [
// ...
'cookieParams' => [
'domain' => 'cookie.monsite.com',
'httpOnly' => true,
],
],
'request' => [ // optional
// ...
'csrfCookie' => [
'domain' => 'cookie.monsite.com',
'httpOnly' => true,
],
],

guzzle and last fm API

I'm using Laravel for about one month and i wanted to try the guzzle module, to get last fm user infos
I've tried this request in my controller :
$client = new \GuzzleHttp\Client(['base_uri' => 'http://ws.audioscrobbler.com/']);
//$client = new \GuzzleHttp\Client();
$response = $client->get('2.0/?method=user.getinfo&user=rj&api_key=xxxxxxxxxx&format=json');
dd($response);
but i've just got this kind of things
Response {#190 ▼
-reasonPhrase: "OK"
-statusCode: 200
-headers: array:11 [▼
"date" => array:1 [▶]
"server" => array:1 [▼
0 => "Apache/2.2.22 (Unix)"
]
"x-web-node" => array:1 [▼
0 => "www223"
]
"access-control-allow-origin" => array:1 [▼
0 => "*"
]
"access-control-allow-methods" => array:1 [▼
0 => "POST, GET, OPTIONS"
]
"access-control-max-age" => array:1 [▼
0 => "86400"
]
"cache-control" => array:1 [▼
0 => "max-age=60"
]
"expires" => array:1 [▶]
"content-length" => array:1 [▼
0 => "642"
]
"connection" => array:1 [▶]
"content-type" => array:1 [▶]
]
-headerLines: array:11 [▶]
-protocol: "1.0"
-stream: Stream {#181 ▼
-stream: :stream {#237 ▼
wrapper_type: "PHP"
stream_type: "TEMP"
mode: "w+b"
unread_bytes: 0
seekable: true
uri: "php://temp"
options: []
}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
}
Could someone help me with an example or something :) ?
For body's contents:
echo $response->getBody();