fbc

fbc

Member Since 2 Years Ago

Experience Points 4,130
Experience Level 1

870 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 8
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

17 Mar
3 days ago

fbc left a reply on How Do You Query This Months Records With Epoch Time?

I ended up solving it like this:

        $date = Carbon::today();

        /* Yearly Realtime Consumption data feed */
        $startthis = Carbon::now()->startOfMonth()->timestamp;
        $endthis = Carbon::now()->endOfMonth()->timestamp;
        $startone = Carbon::now()->subMonths(1)->startOfMonth()->timestamp;
        $endone = Carbon::now()->subMonths(1)->endOfMonth()->timestamp;
        $starttwo = Carbon::now()->subMonths(2)->startOfMonth()->timestamp;
        $endtwo = Carbon::now()->subMonths(2)->endOfMonth()->timestamp;
        $startthree = Carbon::now()->subMonths(3)->startOfMonth()->timestamp;
        $endthree = Carbon::now()->subMonths(3)->endOfMonth()->timestamp;
        $startfour = Carbon::now()->subMonths(4)->startOfMonth()->timestamp;
        $endfour = Carbon::now()->subMonths(4)->endOfMonth()->timestamp;
        $startfive = Carbon::now()->subMonths(5)->startOfMonth()->timestamp;
        $endfive = Carbon::now()->subMonths(5)->endOfMonth()->timestamp;
        $startsix = Carbon::now()->subMonths(6)->startOfMonth()->timestamp;
        $endsix = Carbon::now()->subMonths(6)->endOfMonth()->timestamp;
        $startseven = Carbon::now()->subMonths(7)->startOfMonth()->timestamp;
        $endseven = Carbon::now()->subMonths(7)->endOfMonth()->timestamp;
        $starteight = Carbon::now()->subMonths(8)->startOfMonth()->timestamp;
        $endeight = Carbon::now()->subMonths(8)->endOfMonth()->timestamp;
        $startnine = Carbon::now()->subMonths(9)->startOfMonth()->timestamp;
        $endnine = Carbon::now()->subMonths(9)->endOfMonth()->timestamp;
        $startten = Carbon::now()->subMonths(10)->startOfMonth()->timestamp;
        $endten = Carbon::now()->subMonths(10)->endOfMonth()->timestamp;
        $starteleven = Carbon::now()->subMonths(11)->startOfMonth()->timestamp;
        $endeleven = Carbon::now()->subMonths(11)->endOfMonth()->timestamp;
        $this_months_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startthis, $endthis])->sum('data');
        $one_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startone, $endone])->sum('data');
        $two_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$starttwo, $endtwo])->sum('data');
        $three_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startthree, $endthree])->sum('data');
        $four_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startfour, $endfour])->sum('data');
        $five_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startfive, $endfive])->sum('data');
        $six_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startsix, $endsix])->sum('data');
        $seven_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startseven, $endseven])->sum('data');
        $eight_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$starteight, $endeight])->sum('data');
        $nine_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startnine, $endnine])->sum('data');
        $ten_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$startten, $endten])->sum('data');
        $eleven_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereBetween('time',[$starteleven, $endeleven])->sum('data');

fbc left a reply on How Do You Query This Months Records With Epoch Time?

@CRONIX - Ok I think I figured out the best way to go about this. No I just need to figure out is how to do a ->where('time'(in unix timestamp),$date->copy()->format('m')) something like:

        $this_months_values = (new $propdash->custommenuitems->monthly_real_time_feed)::where('time',$date->copy()->format('m'))->sum('data');

So far if down to this:

        $date = Carbon::today();

        /* Yearly Realtime Consumption data feed */
        $this_months_values = (new $propdash->custommenuitems->monthly_real_time_feed)::where('time',$date->copy()->format('m'))->sum('data');
        $one_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $two_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $three_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $four_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $five_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $six_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $seven_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $eight_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $nine_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $ten_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
        $eleven_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');

        /* Create the chart */
        $yearly_consumption_chart = new HighCharts;
        $yearly_consumption_chart->labels([
            $date->copy()->subMonths(11)->format('F'),
            $date->copy()->subMonths(10)->format('F'),
            $date->copy()->subMonths(9)->format('F'),
            $date->copy()->subMonths(8)->format('F'),
            $date->copy()->subMonths(7)->format('F'),
            $date->copy()->subMonths(6)->format('F'),
            $date->copy()->subMonths(5)->format('F'),
            $date->copy()->subMonths(4)->format('F'),
            $date->copy()->subMonths(3)->format('F'),
            $date->copy()->subMonths(2)->format('F'),
            $date->copy()->subMonths(1)->format('F'),
            $date->copy()->format('F')]);
        $yearly_consumption_chart->dataset('kWh', 'line', [$eleven_month_agos_values,
            $ten_month_agos_values,$nine_month_agos_values,$eight_month_agos_values,
            $seven_month_agos_values,$six_month_agos_values,$five_month_agos_values,$four_month_agos_values,
            $three_month_agos_values,$two_month_agos_values,$one_month_agos_values,$this_months_values]);

fbc left a reply on How Do You Query This Months Records With Epoch Time?

@CRONIX - SUM is awesome!!! I will try to use it!!

I figured 30 because of 30 days in a month, but there are a few months with 31 days, so maybe all() is more appropriate here.

Yes I'm trying to show the cumulative values for the previous year by month. So I need to sum up all values for an entire month for that last 12 months.

You are correct about the

date('m')-2

deal. I would have to write a routine to wrap the negative numbers that will be another adventure and another post for suggestions.

The idea here is to create a chart that show the cumulative value SUM() for the current month, and 11 previous months.

I will keep working on this until I get it right. I know there are helpers to query current and previous months however they are not setup to deal with EPOCH time.

16 Mar
4 days ago

fbc started a new conversation How Do You Query This Months Records With Time Stamp?

I need to SUM all the values for a given month. The beginning of that process is to query the records for that month. I'm trying to do something like this:

        $this_months_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereMonth(Carbon::createFromTimestamp($time)->month, '=', date('m'))->orderBy('time', 'desc')->take(30)->get();

        $one_month_ago_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereMonth(Carbon::createFromTimestamp($time)->month, '=', (date('m')-1))->orderBy('time', 'desc')->take(30)->get();

        $two_month_ago_values = (new $propdash->custommenuitems->monthly_real_time_feed)::whereMonth(Carbon::createFromTimestamp($time)->month, '=', (date('m')-2))->orderBy('time', 'desc')->take(30)->get();

dd results of $this_months_values is:

Collection {#9512 ▼
  #items: array:2 [▼
    0 => Feed115 {#9511 ▼
      #connection: "emoncms"
      #table: "feed_115"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:2 [▼
        "time" => 1552716000
        "data" => 222.314
      ]
      #original: array:2 [▼
        "time" => 1552716000
        "data" => 222.314
      ]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
    1 => Feed115 {#9510 ▼
      #connection: "emoncms"
      #table: "feed_115"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:2 [▼
        "time" => 1552629600
        "data" => 405.903
      ]
      #original: array:2 [▼
        "time" => 1552629600
        "data" => 405.903
      ]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
  ]
}

fbc left a reply on How To Output Only The Difference In Values In An Array To A Chart?

@talinon @cronix I really want to thank you guys for all the helpfulness and answers. I would not have been able to go from a Beginner to a fledgling Intermediate without the help of you Advanced guys.

Problem solved. Thanks.

fbc started a new conversation How To Output Only The Difference In Values In An Array To A Chart?

I have an array that plucks values to an array like so:

        /* Pluck just the wattage values to an array */
        $realtime_data_array = $latestrtfeed->nth(60)->reverse()->pluck('data')->toArray();

results in:

array:150 [▼
  0 => 20277.6
  1 => 20281.4
  2 => 20285.3
  3 => 20289.7
  4 => 20293.8
  5 => 20298.6
  6 => 20303.2
  7 => 20307.4
  8 => 20311.5
  9 => 20315.8
  10 => 20319.8

these value get inputted to the chart like so:

        $realtime_consumption_chart->dataset('kWh', 'line', $realtime_data_array);

the problem is that I only want to show the difference between value 0 and value 1 then difference between value 1 and value 2 and so on and so on.

How would I go about something like that? @cronix @ftiersch

fbc left a reply on How To Properly Offset Time In An Array?

@FTIERSCH - Awesome!!! That worked!

fbc left a reply on How To Properly Offset Time In An Array?

@FTIERSCH - I though it would work, but it didn't. I got:

"DateTime::__construct(): Failed to parse time string (1552657980) at position 8 (8): Unexpected character"

fbc started a new conversation How To Properly Offset Time In An Array?

I have a pluck command that takes the time field from my collection and dumps it into an array like so:

        /* Pluck just the time fields to an array */
        $realtime_labels_array = $latestrtfeed->nth(60)->reverse()->pluck('time')->toArray();

results in:

array:150 [▼
  0 => 1552656650
  1 => 1552657250
  2 => 1552657850
  3 => 1552658450
  4 => 1552659050
  5 => 1552659650
  6 => 1552660250
  7 => 1552660850
  8 => 1552661450
  9 => 1552662050
  10 => 1552662650
  11 => 1552663250
...

I have tried:

$realtime_labels_array->modify('-6 hours');

and

        $realtime_labels_array = (new \DateTime())->modify('-6 hours');

but nothing seems to work on an array.

@Cronix

15 Mar
5 days ago

fbc left a reply on How Do I Apply Date('H:i:s', $this_array)??

@CRONIX - Is there any way to change:

        $latestfeed72 = Feed72::orderBy('time', 'desc')->take(100)->get();

to only query the records in 10 minute intervals? Right now the database contains values at 10 sec intervals.

Maybe there is a skip() that will skip over and read only every 60th record?

14 Mar
6 days ago

fbc left a reply on How Do You Change The Model Name On-the-fly?

@CRONIX - thanks!!!

It seems to work this way as well.

$user = (new $db->relationship->field)::where('id', 1)->get();

This was exactly what I was looking for.

13 Mar
1 week ago

fbc started a new conversation How Do You Change The Model Name On-the-fly?

I want to change the Model Feed72 to a different model depending on which database applies to the property.

The model name that the query needs to use is stored in: $propdash->custommenuitems->real_time_feed which dd into:

"Feed72"

it works fine when I use:

        $latestfeed72 = Feed72::orderBy('time', 'desc')->take(5000)->get();

but fails when I try:

$latestfeed72 = $propdash->custommenuitems->real_time_feed::orderBy('time', 'desc')->take(5000)->get();

or

$latestfeed72 = {!!$propdash->custommenuitems->real_time_feed!!}::orderBy('time', 'desc')->take(5000)->get();

Or should I just write an IF statement to select between datasets when I need to?

11 Mar
1 week ago

fbc left a reply on Where Do I Put My Laravel DB Query In The Sample Source For AMcharts?

@CRONIX - wow man. You just blew my mind and caused my brain to ooze out of my ear man.. I don't think I've advance far enough to understand what JSON is and how to create it.

Is there an example somewhere that shows source code?

fbc started a new conversation Where Do I Put My Laravel DB Query In The Sample Source For AMcharts?

I'm kinda used to how charts work in Laravel Charts(https://charts.erik.cat/), but Timeseries with Zoom is not available in that package. So I need to figure out how to plug my data into this:

<!-- Styles -->
<style>
#chartdiv {
  width: 100%;
  height: 500px;
}

</style>

<!-- Resources -->
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/animated.js"></script>

<!-- Chart code -->
<script>
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);

// Add data
chart.data = generateChartData();

// Create axes
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.minGridDistance = 50;

var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());

// Create series
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueY = "visits";
series.dataFields.dateX = "date";
series.strokeWidth = 2;
series.minBulletDistance = 10;
series.tooltipText = "{valueY}";
series.tooltip.pointerOrientation = "vertical";
series.tooltip.background.cornerRadius = 20;
series.tooltip.background.fillOpacity = 0.5;
series.tooltip.label.padding(12,12,12,12)

// Add scrollbar
chart.scrollbarX = new am4charts.XYChartScrollbar();
chart.scrollbarX.series.push(series);

// Add cursor
chart.cursor = new am4charts.XYCursor();
chart.cursor.xAxis = dateAxis;
chart.cursor.snapToSeries = series;

function generateChartData() {
    var chartData = [];
    var firstDate = new Date();
    firstDate.setDate(firstDate.getDate() - 1000);
    var visits = 1200;
    for (var i = 0; i < 500; i++) {
        // we create date objects here. In your data, you can have date strings
        // and then set format of your dates using chart.dataDateFormat property,
        // however when possible, use date objects, as this will speed up chart rendering.
        var newDate = new Date(firstDate);
        newDate.setDate(newDate.getDate() + i);
        
        visits += Math.round((Math.random()<0.5?1:-1)*Math.random()*10);

        chartData.push({
            date: newDate,
            visits: visits
        });
    }
    return chartData;
}
</script>

<!-- HTML -->
<div id="chartdiv"></div>

This is from: https://www.amcharts.com/demos/line-chart-with-scroll-and-zoom/

08 Mar
1 week ago

fbc left a reply on How Do I Apply Date('H:i:s', $this_array)??

@CRONIX - This is what I've got:

array:100 [▼
  0 => 1552079470
  1 => 1552079460
  2 => 1552079450
  3 => 1552079440
  4 => 1552079430
  5 => 1552079420
  6 => 1552079410
  7 => 1552079400
  8 => 1552079390
  9 => 1552079380
  10 => 1552079370
  11 => 1552079360
  12 => 1552079350
  13 => 1552079340
  14 => 1552079330
  15 => 1552079320
  16 => 1552079310
  17 => 1552079300
  18 => 1552079290
  19 => 1552079280
  20 => 1552079270
  21 => 1552079260
  22 => 1552079250
  23 => 1552079240
  24 => 1552079230

fbc left a reply on How Do I Apply Date('H:i:s', $this_array)??

@CRONIX - I tried this:

        $realtime_labels_array = array_map(function($t) { return date("H:i:s", strtotime($t)); }, $realtime_labels_array);

but it turned all my labels to zeros.

fbc left a reply on How Do I Apply Date('H:i:s', $this_array)??

@CRONIX - "time":1549169750000,"data":"23527"

fbc left a reply on How Do I Apply Date('H:i:s', $this_array)??

@D9705996 - Thanks!!! I tried it but now my Y axis on my chart says "object object"

        $latestfeed72 = Feed72::orderBy('time', 'desc')->take(100)->get();
        $realtime_labels_array = $latestfeed72->pluck('time')->toArray();
        $realtime_data_array = $latestfeed72->pluck('data')->toArray();

        $realtime_consumption_chart = new ChartJS;
        $realtime_consumption_chart->labels($realtime_labels_array);
        $realtime_consumption_chart->dataset('My dataset', 'line', $realtime_data_array);

This is what the complete use is like..

the time column is in UNIX/EPOCH time. This is why I'm trying to convert it.

fbc started a new conversation How Do I Apply Date('H:i:s', $this_array)??

I have this array:

$realtime_labels_array = $latestfeed72->pluck('time')->toArray();

I'd like to pluck 'time' in this format

date('H:i:s', $this_array)
04 Mar
2 weeks ago

fbc left a reply on How To Query Through Nested Relationships? The Laravel Eloquent Way.

@CRONIX - I got it working!

Yes it does worry me that I may not be using the most efficient query structure.. but until I figure out how to add a user function to my Company Model, I don't think I will have a solution for that.

I ended up with this:

        $Regions = Region::where('company_id','=', $company->id)->get();
        foreach ($Regions as $region){
            $Departments = Department::where('region_id','=', $region->id)->get();
            foreach ($Departments as $department){
                $Teams = Team::where('department_id','=', $department->id)->get();
                foreach ($Teams as $team){
                    $Users = User::where('team_id','=', $team->id)->get()->toArray();
                }
            }

        }

        return view('company.edit', compact('company', 'Users'));

and this in the blade:

                        @foreach ($Users as $user)
                        <option value="{{$user['id']}}">{{$user['name']}}</option>
                        @endforeach 

fbc left a reply on How To Query Through Nested Relationships? The Laravel Eloquent Way.

@CRONIX - You mentioned I might create a user in the company model to get them all. How would I go about creating one of those?

fbc left a reply on How To Query Through Nested Relationships? The Laravel Eloquent Way.

@CRONIX - However now I'm getting an error: Trying to get property of non-object for my blade controller. i guess because my data is in an array, I can't use it exactly as i do when I pass data from a query.

                        @foreach ($users as $user)
                        <option value="{{$user->id}}">
                            {{--{{$user->team->department->region->company->name}}-{{$user->team->department->region->name}}-{{$user->team->department->name}}-{{$user->team->name}}--}}
                        </option>
                        @endforeach

It's complaining that $user->id is a non-object.

If I dd $user I get:

array:6 [▼
  0 => array:6 [▼
    "id" => 20
    "name" => "abcuser1"
    "email" => "[email protected]"
    "team_id" => 3
    "created_at" => "2019-03-04 14:50:08"
    "updated_at" => "2019-03-04 15:23:46"
  ]
  1 => array:6 [▼
    "id" => 21
    "name" => "abcuser2"
    "email" => "[email protected]"
    "team_id" => 3
    "created_at" => "2019-03-04 14:50:50"
    "updated_at" => "2019-03-04 15:24:09"
  ]
  2 => array:6 [▼
    "id" => 22
    "name" => "abcuser3"
    "email" => "[email protected]"
    "team_id" => 3
    "created_at" => "2019-03-04 14:52:08"
    "updated_at" => "2019-03-04 15:24:16"
  ]
  3 => array:6 [▼
    "id" => 23
    "name" => "abcuser4"
    "email" => "[email protected]"
    "team_id" => 3
    "created_at" => "2019-03-04 14:54:25"
    "updated_at" => "2019-03-04 15:24:23"
  ]
  4 => array:6 [▼
    "id" => 24
    "name" => "abcuser6"
    "email" => "[email protected]"
    "team_id" => 3
    "created_at" => "2019-03-04 14:57:03"
    "updated_at" => "2019-03-04 15:24:30"
  ]
  5 => array:6 [▼
    "id" => 25
    "name" => "abcuser5"
    "email" => "[email protected]"
    "team_id" => 3
    "created_at" => "2019-03-04 14:57:59"
    "updated_at" => "2019-03-04 15:24:36"
  ]
]

fbc left a reply on How To Query Through Nested Relationships? The Laravel Eloquent Way.

@CRONIX - I think I solved it with:

        $Regions = Region::where('company_id','=', $company->id)->get();
        foreach ($Regions as $region){
            $Departments = Department::where('region_id','=', $region->id)->get();
            foreach ($Departments as $department){
                $Teams = Team::where('department_id','=', $department->id)->get();
                foreach ($Teams as $team){
                    $users = User::where('team_id','=', $team->id)->get();
                }
            }

        }

fbc left a reply on How To Query Through Various Levels Of Relationships? The Laravel Eloquent Way.

@CRONIX - That didn't work for me , but i updated the question with more detailed information.

fbc started a new conversation How To Query Through Various Levels Of Relationships?

I have a relationship that is almost 5 levels deep. For example:

{{ $user->team->department->region->company->name ?? ''}}

How would I go about querying all users that belong to a company?

$users = User::where($user->team->department->region->company->, '=', 1)->all(); ?????

20 Feb
1 month ago

fbc left a reply on Standard Deviation Funtion?

@CRONIX - I just did the helper function and called it like this:

$AUT2std = self::Stand_Deviation($AUT2pluck_array);

fbc started a new conversation Standard Deviation Funtion?

I am trying to get the standard deviation for an array like this:

        //put all GW1 records into an array
        $GW1pluck_array = $results->pluck('GW1')->toArray();
        //get standard deviation for all GW1's in the array
        $GW1std = stats_standard_deviation($GW1pluck_array);

stats_standard_deviation does not exist as a laravel function. Is there any such function I can use? Package I can install?

16 Feb
1 month ago

fbc left a reply on Does Any Time Series Adjustable Chart Package Exist For Laravel?

@DIGIPRODUCT - I don't see anything that looks like the example I gave you.. Look at the dragable window above the chart.. I can't find any chart.js chart that has that.

15 Feb
1 month ago

fbc started a new conversation Does Any Time Series Adjustable Chart Pakages Exist For Laravel?

Is there a Laravel package that would make it easy to implement time series data charts like this one: https://www.amcharts.com/demos/area-with-time-based-data/

Maybe I missed something in Lavacharts or Laravel Charts packages, but I can't seem to find a darn thing that will handle time series data.

12 Feb
1 month ago

fbc left a reply on Proper Way To Sum Two Variables In A Cyclic Manner?

@VILFAGO - Laravel was complaining that $val_sum need to be an existing variable with a value before it could add something to it. So that is why I added $val_sum = 0;

fbc started a new conversation Proper Way To Sum Two Variables In A Cyclic Manner?

I've been using this:

            //sum the vals in the query
            $val_sum = '0';
            foreach ($nrcan_consump_records_options as $option) {
                $val_sum = $val_sum + $option->val;
            };

however, PHPSTORM complains that this is an incorrect method. After googling around I find that SUM might be what I'm looking for.

So would I implement it like this?

            //sum the vals in the query
            $val_sum = '0';
            foreach ($nrcan_consump_records_options as $option) {
                return $val_sum->sum() + $option->val->sum();
            };

Is that correct?

09 Feb
1 month ago

fbc started a new conversation Passing Variable Through RESOURCE ROUTE CREATE Possible?

I have an app that permits surveys one the survey is commissioned.

I need to pass the commissioned survey id to the CREATE function but I'm getting an error as follows:

"Too few arguments to function App\Http\Controllers\TeamAssessmentController::create(), 0 passed and exactly 1 expected"

My route looks like this:

|        | GET|HEAD  | teamassessment/create                | teamassessment.create  | App\Http\Controllers\[email protected]              | web,auth                                     |

The blade that calls the route looks like this:

                    @if (count($surveys) > 0)
                        <div class="alert alert-warning" role="alert">
                            You have surveys waiting.
                            @foreach ($surveys as $survey)
                                <br>Survey ID:&nbsp;{{$survey->id}} &nbsp;-&nbsp;&nbsp;Type:&nbsp;
                                @if ($survey->survey->survey_type === 0)
                                    <?php $surveyid=$survey->id ?>
                                    <a href="{{ route('teamassessment.create',compact('surveyid')) }}">Team Assessment</a>
                                @endif
                            @endforeach
                        </div>
                    @endif

the function in the controller looks like this:

    public function create($surveyid)
    {
        return view('teamassessment.take',compact('surveyid'));
    }

What is the best way around this problem? Custom web route maybe? Is the laravel approved way to do this?

04 Feb
1 month ago

fbc started a new conversation Best Practice To Avoid "property Of Non-object"?

I have a Controller that polls a users consumption history to generate a graph. Not every user will put their consumption data into the program right-away.

So the query beginning with "$electricalconsumption = Consumption_history::orderBy.." will not have any values?

        //get latest electrical consumption value
        $electricalconsumption = Consumption_history::orderBy('end_period', 'desc')
            ->where('propertyid',$propertyid)
            ->where('resource_type',1)
            ->first();

        //create percentages
        $space_heating_percentage = $electricalconsumption->units_consumed * $space_heating_decimal;
        $hot_water_percentage = $electricalconsumption->units_consumed * $hot_water_decimal;
        $lighting_percentage = $electricalconsumption->units_consumed * $lighting_decimal;
        $space_cooling_percentage = $electricalconsumption->units_consumed * $space_cooling_decimal;
        $auxiliary_motor_percentage = $electricalconsumption->units_consumed * $auxiliary_motor_decimal;
        $auxiliary_equipment_percentage = $electricalconsumption->units_consumed * $auxiliary_equipment_decimal;

        //create chart
        $polar_consumption_chart = new PolarConsumption;
        $polar_consumption_chart->labels(['Space Heating', 'Hot Water', 'Lighting','Space Cooling','Auxiliary Motors','Auxiliary Equipment']);
        $polar_consumption_chart->dataset('Consumption', 'polarArea', [$space_heating_percentage,$hot_water_percentage,
            $lighting_percentage,$space_cooling_percentage,$auxiliary_motor_percentage,$auxiliary_equipment_percentage]);

Should I create and If-Then for @electricalconsumption? Or does Laravel have a more Eloquent(pun intended) way of managing these problems?

28 Jan
1 month ago

fbc left a reply on How Do I Get A Count Of How Many Columns Are (or Aren't) Null In A Query?

@CRONIX - Wow, that is exactly where I was going with it. Thanks!!!

27 Jan
1 month ago

fbc left a reply on How Do I Get A Count Of How Many Columns Are (or Aren't) Null In A Query?

@DRFRAKER - I'm using Linux. So installing microsoft assets might be a problem. Thanks though.

fbc left a reply on How Do I Get A Count Of How Many Columns Are (or Aren't) Null In A Query?

@DRFRAKER - For example: How many profile questions has the user not filled out.

I'm looking for something like: {{ $user->profile->count(empty columns) }}

fbc left a reply on How Do I Get A Count Of How Many Columns Are (or Aren't) Null In A Query?

For example: How many profile questions has the user not filled out.

I'm looking for something like: {{ $user->profile->count(empty columns) }}

fbc left a reply on How Do I Get A Count Of How Many Columns Are (or Aren't) Null In A Query?

@DRFRAKER - I want to count the empty columns in the returned row. My query will always return one row.

fbc started a new conversation How Do I Get A Count Of How Many Columns Are (or Aren't) Null In A Query?

Basically I have a survey with 30 questions that creates a record in a database. Sometimes people forget they only answered 25% of the survey questions.

How do I get a count of how many columns where left 'null' in a query?

24 Jan
1 month ago

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - Oh yeah for sure!!!

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - Ahh $propdash->profile->square_footage is NULL in the DB.. someone did not fill one out..

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - To be brief and to help you focus on the issue I try to give you the snippets with the problem instead of making people read through a lot of manucia.

    public function singledash($propertyid)
    {
        //find the property record
        $propdash = Property::where('id', $propertyid)->first();
//        foreach ($propdash as $property) {
//            $property_sqft = $property->profile->square_footage;
//        }
//        dd($property_sqft);

        //Realtime Consumption data feed
        $latestfeed72 = Feed72::orderBy('time', 'desc')->take(10)->get();


        //electrical consumption data chart
        $thismonthsconsumption = Consumption_history::orderBy('end_period', 'desc')->where('resource_type',1)->take(5)->get();
        $nrcan = Mock_data_records::orderBy('date_end', 'desc')
            ->whereHas( 'property', function ($query) use($propdash) {
                $query->where('type', 'Commercial')
                    ->whereBetween('building_area_sqft', [
                        ($propdash->profile->square_footage * .8), // -20%
                        ($propdash->profile->square_footage * 1.2), // +20%
                    ])
                ;
            } )
            ->take(5)->get();


        $consumption_array = $thismonthsconsumption->reverse()->pluck('units_consumed')->toArray();
        $consumption_date_array = $thismonthsconsumption->reverse()->pluck('end_period')->toArray();
        $nrcan_average = $nrcan->reverse()->pluck('el_total')->toArray();

        $elecconsump_chart = new ElecConsump;
        $elecconsump_chart->labels($consumption_date_array);
        $elecconsump_chart->dataset('My Consumption', 'area', $consumption_array);
        $elecconsump_chart->dataset('NRCAN Average', 'area', $nrcan_average);

        return view('singledash',compact('propdash','latestfeed72','elecconsump_chart'));
    }

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - Yeah, I've used it before, and I use data form it in the Blade View that gets called via COMPACT('propdaash')

    public function profile() {

        return $this->hasOne('App\Profile', 'propertyid', 'id');

    }

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - Scratch that,, it just generates another error.

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - wow, that DD thing is awesome, I'm gonna have to take a note of that. Yup it shows NULL.

So do you think:

        //find the property record
        $propdash = Property::where('id', $propertyid)->first();
    foreach ($propdash as $property) {
    $property_sqft = $property->profile->square_footage;
    }

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - My DEBUG bar shows: select * from "mock_data_records" where exists (select * from "mock_data" where "mock_data_records"."property_id" = "mock_data"."property_id" and "type" = 'Commercial' and "building_area_sqft" between '0' and '0') order by "date_end" desc limit 5

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - You da man! That fix that problem, however I'm getting 0 records returned now..

How to I check that $propdash->profile->square_footage actually has a value?

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - @dalma Yeah, is that bad? I was told you want to do as little as you can in your view and put all your logic in the controller.

fbc started a new conversation Using Relationships In A Controller Possible?

I have no problem using: {{$property->profile->square_footage}} in the blade view that get called as I do a @foreach ($propdash as $property).

It's only retrieving one record.

So why would I not be able to do this?

    public function singledash($propertyid)
    {
        //find the property record
        $propdash = Property::where('id', $propertyid)->first();
        echo $propdash->profile->square_footage;

I want to use $propdash->profile->square_footage in a variance query like so:

$results = Model::whereBetween('column', [
    ($propdash->profile->square_footage * .8), // -20%
    ($propdash->profile->square_footage * 1.2), // +20%
])->get();

Instead I get a property Non Object error.