Need array instead of object in laravel using raw Query like DB::select("SELECT * FROM table");
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , In laravel when i use DB::select("SELECT * FROM table"); It return a object,but i need a array. So how can i get a array instead of object? , Please Try this one. \Illuminate\Support\Facades\DB::setFetchMode(PDO::FETCH_ASSOC);
$values=\Illuminate\Support\Facades\DB::select("select * from your_table");
\Illuminate\Support\Facades\DB::setFetchMode(PDO::FETCH_CLASS);
var_dump($values);
|
Using array values to select database table in laravel
Date : March 29 2020, 07:55 AM
it fixes the issue Yes, You should use whereIn for array. In fact, whereIn takes second parameter as array of values for specified column. Product::whereIn('product_id', $value);
|
Laravel [QUERY] how to select contents from table 1 where condition must meet in table 2 and table 3
Tag : php , By : lietkynes
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I am stuck in building a query where I need to select items from table 1 if the condition is met on table 2 and table 3. , This isn't tested, but it will be something like the following: $query = Company::query()
->select(['company.name','company.location'])
->leftJoin('services', 'services.company_id', '=', 'company.company_id')
->leftJoin('date', 'date.service_id', '=', 'services.service_id')
->where('services.service_name', $servicename)
->where('date.service_date', $servicedate);
|
convert a nested array to a specific select box in laravel
Tag : php , By : Pancilobak
Date : March 29 2020, 07:55 AM
Any of those help Here is a way to implement this using pure PHP with a recursive function... First we define the array of categories: $categories = [
['id' => 1, 'name' => 'TV & Home Theather'],
['id' => 2, 'name' => 'Tablets & E-Readers'],
['id' => 3, 'name' => 'Computers', 'children' => [
['id' => 4, 'name' => 'Laptops', 'children' => [
['id' => 5, 'name' => 'PC Laptops'],
['id' => 6, 'name' => 'Macbooks (Air/Pro)']
]],
['id' => 7, 'name' => 'Desktops'],
['id' => 8, 'name' => 'Monitors']
]],
['id' => 9, 'name' => 'Cell Phones']
];
function printCats($categories, $parent = NULL) {
while ($category = array_shift($categories)) {
$catName = ($parent ? $parent.' >> ' : '').$category['name'];
print("<option value='{$category['id']}'>{$catName}</option>\n");
if (isset($category['children']))
printCats($category['children'], $catName);
}
}
printCats($categories);
<option value='1'>TV & Home Theather</option>
<option value='2'>Tablets & E-Readers</option>
<option value='3'>Computers</option>
<option value='4'>Computers >> Laptops</option>
<option value='5'>Computers >> Laptops >> PC Laptops</option>
<option value='6'>Computers >> Laptops >> Macbooks (Air/Pro)</option>
<option value='7'>Computers >> Desktops</option>
<option value='8'>Computers >> Monitors</option>
<option value='9'>Cell Phones</option>
|
Convert table with select fields to js array
Date : March 29 2020, 07:55 AM
will help you Instead of getting all the table you could get only the selectors using document.getElementsByClassName o document.getElementsByTagName Then you can iterate (but its NOT an iterable you cannot use map or reduce) and get the selected value of every select. function extractTable() {
var tableItems = document.getElementsByClassName("field_select");
var tableRows = [];
for(var i = 0; i<tableItems.length; i++){
var e = tableItems[i]
var option = e.options[e.selectedIndex].value;
console.log(option)
tableRows.push(option);
}
// Create a JSON
let jsonTable = JSON.stringify(tableRows, null, 2);
console.log(jsonTable);
};
|