I used Eloquent query to extract the below table
**$ user = User::all()
**
id q1 q2 q3 q4 q5 q6 q7
0 0.01 0.8 null 0.9 null 0.9 0.1
1 0.8 null null 1 null 1 null
2 null null null 0.03 null 0.03 null
3 0.04 0.4 null 0.9 null 0.5 null
4 null 0.67 null 0.8 null 9 0.8
5 0.07 0.9 null 0.6 null 10 null
6 1 null null 1 null 0.05 null
The final table should look like this
id q1 q2 q4 q6 q7
0 0.01 0.8 0.9 0.9 0.1
1 0.8 null 1 1 null
2 null null 0.03 0.03 null
3 0.04 0.4 0.9 0.5 null
4 null 0.67 0.8 9 0.8
5 0.07 0.9 0.6 10 null
6 1 null 1 0.05 null
I need to query the model in the laravel by removing the column that has only null values. Any help would be appreciated.
2
Answers
Untested:
On your Controller:
at this point, you’ll know what column is true or false. You will only display all columns that has
true
value.Throw the $users, $q1, $q2, $q3, $q4, $q5, $q6, $q7 variables on blade files.
UPDATE:
This one is now tested working.
I only tweaked some codes for the blade file as follows:
This help bases on this idea: All null values will become only one null value after using
array_unique([$array_of_null_values])
.So you can do like me as:
Set the content of Controller
appHttpControllersBasicController.php
.Reuse $includes from controller as blade
resourcesviewsprocess.blade.php
.And you will get desired result.