fbc

fbc

Member Since 2 Years Ago

Experience Points 4,410
Experience Level 1

590 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.

06 May
2 weeks ago

fbc left a reply on File Upload Not Being Stored

I couldn't get that function to work for the life of me.

ended up going with this:

        if($request->hasFile('audit')){
            $audit = new Audit;

            $file = $request->file('audit');
            $fileName = $file->getClientOriginalName();
            $request->file('audit')->move(public_path('/uploads/audits/'),$fileName);

            $audit->property_id = $request->propertyid;
            $audit->title = $request->title;
            $audit->filename = $fileName;
            $audit->type = $request->audit_type;
            $audit->save();
        }

fbc started a new conversation File Upload Not Being Stored

I am trying to upload a file and save it.

There is no error, however no file is saved.

This is the save function:

        // Handle the user upload of a file
        if($request->hasFile('audit')){
            $audit = $request->file('audit');
            $filename = time() . '.' . $audit->getClientOriginalExtension();
            Storage::put( public_path('/uploads/audits/' . $filename ), $request->file('audit') );

            $audit = new Audit;
            $audit->property_id = $request->propertyid;
            $audit->title = $request->title;
            $audit->filename = $filename;
            $audit->type = $request->audit_type;
            $audit->save();
        }

I took my code for saving an avatar and tried to alter it to work with regular files instead of just images.

Here is the original code for that function I started off with:

    public function update_avatar(Request $request){

        // Handle the user upload of avatar
        if($request->hasFile('avatar')){
            $avatar = $request->file('avatar');
            $filename = time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)->resize(300, 300)->save( public_path('/uploads/avatars/' . $filename ) );

            $user = Auth::user();
            $user->avatar = $filename;
            $user->save();
        }

        return view('profile', array('user' => Auth::user()) );

    }

fbc started a new conversation Sorry Page Not Found.. View File Not Found

My route is define as:

Route::resource('/property/audit','AuditController');

php artisan route:list results in:

|        | POST      | property/audit                                          | audit.store                       | App\Http\Controllers\[email protected]                                | web                                          |
|        | GET|HEAD  | property/audit                                          | audit.index                       | App\Http\Controllers\[email protected]                                | web                                          |
|        | GET|HEAD  | property/audit/create                                   | audit.create                      | App\Http\Controllers\[email protected]                               | web                                          |
|        | DELETE    | property/audit/{audit}                                  | audit.destroy                     | App\Http\Controllers\[email protected]                              | web                                          |
|        | PUT|PATCH | property/audit/{audit}                                  | audit.update                      | App\Http\Controllers\[email protected]                               | web                                          |
|        | GET|HEAD  | property/audit/{audit}                                  | audit.show                        | App\Http\Controllers\[email protected]                                 | web                                          |
|        | GET|HEAD  | property/audit/{audit}/edit                             | audit.edit                        | App\Http\Controllers\[email protected]                                 | web      

I'm calling the route like this:

                        <a href="{{route('audit.show',$propdash->id)}}">

which results in an URL like this:

http://xxx/property/audit/25

my controller looks like this:

    public function show(Audit $audit)
    {
        $levelone=Audit::where(property_id,$audit)->where(type,1);
        $leveltwo=Audit::where(property_id,$audit)->where(type,2);
        $levelthree=Audit::where(property_id,$audit)->where(type,3);

        return view('audit.show',compact('levelone','leveltwo','levelthree'));
    

my show.blade.php is in /resources/views/audit/

my permissions are correct. I can't understand why it can't see the view file.

12 Apr
1 month ago

fbc started a new conversation Laravel Charts To PDF Possible??

I am using Laravel charts to generate charts for a report on the screen. However, I would like for those charts to appear in a PDF report as well.

I installed barryvdh/laravel-dompdf and have created PDF reports but have yet been able to create one that includes the charts. The area where the chart should be just shows up as blank space.

What is the easiest route to get a chart to show up in a PDF files?

09 Apr
1 month ago

fbc started a new conversation Any Guide Or Chart Library That Allows For Dynamically Updating Chart?

I would like to make a self updating real-time chart but neither LaravelCharts(currently use) nor Lavacharts show any example of supporting any such an animal. I'm not a Javascript proficient person, yet have use Laravel to create cool stuff. Is there any guide I can read for Laravel that will help me create a realtime chart with having to learn Javascript?

26 Mar
1 month ago

fbc left a reply on Webscraping Help With Goutte.

@DEVMASTER - I can't seem to extract the proper values with:

Route::get('hdtuto', function() {

    $crawler = Goutte::request('GET', 'http://ets.aeso.ca/ets_web/ip/Market/Reports/CSDReportServlet');

    $aeso_data = $crawler->filter('TABLE > TR > TD');

    dd($aeso_data);

});

fbc left a reply on Webscraping Help With Goutte.

@DEVMASTER - I used this guide to install Goutte: https://hdtuto.com/article/php-laravel-56-website-scraper-using-goutte

I am using Laravel 5.7, I don't know if that is going to be a problem.

I am getting a blank screen when trying to run that example in the guide./ My error log shows this:

[Tue Mar 26 13:57:57.775899 2019] [php7:error] [pid 8920] [client 0.0.0.0:43482] PHP Fatal error:  Uncaught RuntimeException: A facade root has not been set. in /home/ubuntu/app.domain.com/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:220\nStack trace:\n#0 /home/ubuntu/app.domain.com/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(396): Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac...', Array)\n#1 /home/ubuntu/app.domain.com/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(373): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths()\n#2 /home/ubuntu/app.domain.com/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(288): Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\Exception\HttpException))\n#3 /home/ubuntu/app.domain.com/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(187): Illuminate\Foundation\Exceptions\Handler->prepareResponse(Object(Illumina in /home/ubuntu/app.domain.com/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 220
24 Mar
1 month ago

fbc left a reply on Webscraping Help With Goutte.

@DEVMASTER - I'm on my way to solving it, I've already gathered all the elements I think I need to solve it.

I'll be testing a sample controller in a moment.

I really appreciate your willingness to help. If I run into an error somewhere with my code. I will definitely post it here and tag you on it.. Thank you.

fbc started a new conversation Webscraping Help With Goutte.

I have installed Goutte. The docs show extracting data like so:

// Get the latest post in this category and display the titles
$crawler->filter('h2 > a')->each(function ($node) {
    print $node->text()."\n";
});

however the webpage I'm trying to scrap for one value has multiple tables and values on one line like so:

        <TD VALIGN="TOP" WIDTH="40%">
            <TABLE BORDER="1" WIDTH="100%">
                <TR>
                    <TH COLSPAN="4"><CENTER><B>GENERATION</B></CENTER></TH>
                </TR>
                <TR>
                    <TD BGCOLOR="#336699"> <P ALIGN=RIGHT><FONT SIZE="-2" FACE="Arial,Helvetica" COLOR="White">GROUP</FONT></TD>
                    <TD BGCOLOR="#336699"> <P ALIGN=RIGHT><FONT SIZE="-2" FACE="Arial,Helvetica" COLOR="White">MC</FONT></TD>
                    <TD BGCOLOR="#336699"> <P ALIGN=RIGHT><FONT SIZE="-2" FACE="Arial,Helvetica" COLOR="White">TNG</FONT></TD>
                    <TD BGCOLOR="#336699"> <P ALIGN=RIGHT><FONT SIZE="-2" FACE="Arial,Helvetica" COLOR="White">DCR</FONT></TD>
                </TR>
                <TR><TD>COAL</TD><TD>5723</TD><TD>3514</TD><TD>70</TD></TR>
<TR><TD>GAS</TD><TD>7657</TD><TD>5406</TD><TD>77</TD></TR>
<TR><TD>HYDRO</TD><TD>894</TD><TD>160</TD><TD>220</TD></TR>
<TR><TD>OTHER</TD><TD>438</TD><TD>228</TD><TD>0</TD></TR>
<TR><TD>WIND</TD><TD>1445</TD><TD>212</TD><TD>0</TD></TR>
<TR><TD>TOTAL</TD><TD>16157</TD><TD>9520</TD><TD>367</TD></TR>

            </TABLE>
        </TD>

so I need to extract the SECOND values on each of the lines:

                <TR><TD>COAL</TD><TD>5723</TD><TD>3514</TD><TD>70</TD></TR>
<TR><TD>GAS</TD><TD>7657</TD><TD>5406</TD><TD>77</TD></TR>
<TR><TD>HYDRO</TD><TD>894</TD><TD>160</TD><TD>220</TD></TR>
<TR><TD>OTHER</TD><TD>438</TD><TD>228</TD><TD>0</TD></TR>
<TR><TD>WIND</TD><TD>1445</TD><TD>212</TD><TD>0</TD></TR>

I assume may need something like this? But this will give be every value I just need the second value on the Coal line.

$coal->filter('TABLE > TR > TD')->each(function ($node) {
    $coalvalue = $node->text();
});
17 Mar
2 months 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
2 months 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
2 months 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
2 months 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
2 months 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
2 months 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
2 months 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 months 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
3 months 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
3 months 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
3 months 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
3 months 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
3 months 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
3 months 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
3 months 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
3 months 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
3 months ago

fbc left a reply on Undefined Variable: Propdash" Error

@DALMA - Oh yeah for sure!!!