fbc

fbc

Member Since 2 Years Ago

Experience Points 5,090
Experience Level 2

4,910 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-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

22 Jul
20 hours ago

fbc started a new conversation Design Your Own Chart Plugin Exists??

Is there some kind of a chart addon that will allow the user to build their own chart?

Something where you can specify the data feeds, and the user can click what data they want to chart on each axis? and possibly / ideally be able to download a CSV file of that data?

13 Jul
1 week ago

fbc left a reply on Querying Through Several Levels Of Relationships

I think I figured it out:

        $company = Company::find($company->id);
        $users = [];

        foreach ($company->region as $region)
        {
            foreach ($region->department as $department)
            {
                foreach ($department->team as $team)
                {
                    foreach ($team->user as $userteam) {
                            $users [] = $userteam->user;
                    }
                }
            }
        }

fbc started a new conversation Querying Through Several Levels Of Relationships

I'm trying to get all the user of a particular company. However a company can have many regions, that can have many departments, that can have many teams and users that can belong to multiple teams.

Relationships are setup as so: App/Company.php

class Company extends Model
{
    public function region() {

        return $this->hasMany('App\Region', 'company_id', 'id');

    }

App/Region.php

class Region extends Model
{
    public function company() {

        return $this->hasOne('App\Company', 'id', 'company_id');

    }
    public function department() {

        return $this->hasMany('App\Department', 'region_id', 'id');

    }

App/Department.php

class Department extends Model
{
    public function region() {
        return $this->hasOne('App\Region', 'id', 'region_id');
    }

    public function team() {
        return $this->hasMany('App\Team', 'department_id', 'id');
    }

App/Team.php

class Team extends Model
{
    public function department() {
        return $this->hasOne('App\Department', 'id', 'department_id');
    }

    public function user() {
        return $this->hasMany('App\UserTeam', 'team_id', 'id');
    }

App/UserTeam.php

class UserTeam extends Model
{
    protected $table = 'userteam';
    public function user() {
        return $this->hasOne('App\User', 'id', 'user_id');
    }
    public function team() {
        return $this->hasOne('App\Team', 'id', 'team_id');
    }

App/User.php

class User extends Authenticatable
{
    public function team() {
        return $this->hasMany('App\UserTeam', 'user_id', 'id');
    }

I had previously taken a stab at it, but it's not really an efficient query and it's not really using the relationships.

        $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'));
10 Jul
1 week ago

fbc started a new conversation Error Handling For NGINX BADGATEWAY

My application pulls JSON data from an API like so:

            /* Pull the Feed */
            $monthlyrtfeed = json_decode(file_get_contents(
                'http://xxxx.com?meters=' . $monthly_live_device->feed_id . '&ver=v4&key=' . $monthly_live_device->api_key . '&format=json&report=dy&limit=100&start_date='.$startDayYYYYMMDD.'0000&end_date='.$endDayYYYYMMDD.'0000&fields=Pulse_Cnt_1*'
            ), true);

however the providers API sometimes goes down and I'm left with an ugly error and no continuity.

It would be great if I could figure out how to get it to say something like API is not responding at the moment.

if I try opening the API link directly, I get NGINX BAD GATEWAY. The laravel error I get is:

ErrorException thrown with message "file_get_contents(http://xxx.com/summary?meters=350002879&ver=v4&key=NjUyNDQyMjE6SzhNM1B3cnE&format=json&report=dy&limit=100&start_date=201907010000&end_date=201908010000&fields=kWh_Tot*): failed to open stream: HTTP request failed! "

Stacktrace:
#59 ErrorException in /home/ubuntu/app.com/app/Http/Controllers/PropertyController.php:2318
#58 file_get_contents in /home/ubuntu/app.com/app/Http/Controllers/PropertyController.php:2318
#57 App\Http\Controllers\PropertyController:get_monthly_ekm_elec in /home/ubuntu/app.com/app/Http/Controllers/PropertyController.php:265
#56 App\Http\Controllers\PropertyController:singledash in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#55 call_user_func_array in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#54 Illuminate\Routing\Controller:callAction in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
#53 Illuminate\Routing\ControllerDispatcher:dispatch in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php:219
#52 Illuminate\Routing\Route:runController in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php:176
#51 Illuminate\Routing\Route:run in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php:680
#50 Illuminate\Routing\Router:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#49 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
#48 Illuminate\Routing\Middleware\SubstituteBindings:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#47 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#46 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:43
#45 Illuminate\Auth\Middleware\Authenticate:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#44 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#43 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:75
#42 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#41 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#40 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#39 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#38 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#37 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:56
#36 Illuminate\Session\Middleware\StartSession:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#35 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#34 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#33 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#32 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#31 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:66
#30 Illuminate\Cookie\Middleware\EncryptCookies:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#29 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#28 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#27 Illuminate\Pipeline\Pipeline:then in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php:682
#26 Illuminate\Routing\Router:runRouteWithinStack in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php:657
#25 Illuminate\Routing\Router:runRoute in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php:623
#24 Illuminate\Routing\Router:dispatchToRoute in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php:612
#23 Illuminate\Routing\Router:dispatch in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
#22 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#21 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php:65
#20 Barryvdh\Debugbar\Middleware\InjectDebugbar:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#19 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#18 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/fideloper/proxy/src/TrustProxies.php:57
#17 Fideloper\Proxy\TrustProxies:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
#5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#2 Illuminate\Pipeline\Pipeline:then in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /home/ubuntu/app.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in /home/ubuntu/app.com/public/index.php:55

How could I intercept this error and tell it to display something else ?

fbc left a reply on How Do You Add An Element To An Array Without A Key Value?

found it! $arr = array("black","blue"); array_push($arr, "white");

fbc started a new conversation How Do You Add An Element To An Array Without A Key Value?

I've been using the ARR helper to get this done but the problem is that I just want to add to the array without having to specify the key value..

$arr = []
$arr = Arr::add($arr,0,'Bob');
$arr = Arr::add($arr,0,'Larry');

only gets me:

array:1 [▼
  0 => "Bob"
]

in order to get Larry I have to do:

$arr = []
$arr = Arr::add($arr,0,'Bob');
$arr = Arr::add($arr,1,'Larry');

So I basically have to number them. i tried append instead of add but it didn't exist. Any other why to get this done??

fbc left a reply on Returning Multiple Results Possible When Calling Function Possible?

I can't tell you why this works:

[$one, $two, $three] = test();

but it does... I tried list() though and it works just as well.

fbc left a reply on Returning Multiple Results Possible When Calling Function Possible?

I think I solved it with:


I don't know if it's functional, but at least it does not give me an error.

fbc left a reply on Returning Multiple Results Possible When Calling Function Possible?

the lists() function gives me an error.. I think that could be wrong or something. "Can't use function return value in write context"

fbc left a reply on Returning Multiple Results Possible When Calling Function Possible?

what is if the variables are array themselves like:

return [$dates, $times];

will it combine them all or mix them together or something?

fbc left a reply on Returning Multiple Results Possible When Calling Function Possible?

what is if the variables are array themselves like:

return [$dates, $times];

will it combine them all or mix them together or something?

fbc started a new conversation Returning Multiple Results Possible When Calling Function Possible?

Right now I make calls that look like this?

$corrected_date = $this->get_date_correction($a,$b);

and the get_date_correction function ends something like this:

return $corrected_date;

but what about if you want to get multiple results back? Can I do something like this?

$date,$time = $this->parse_feed($feed)

and return multiple results like this?

return $date,$time;
09 Jul
1 week ago

fbc started a new conversation Is Extending A Model To Multiple Classes Possible?

To use Mongodb my model needs to have:

...
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent
...

my User Model looks like this:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Authenticatable
{
    use Notifiable, HasApiTokens;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function property() {

        return $this->hasMany('App\Property', 'userid');

    }
}

when I change Authenticatable to Eloquent I get this error:

Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given, called in /home/ubuntu/xxx/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 377

when I leave it as Authenticatable, I get this error:

"Call to a member function prepare() on null"

which is normally what happens when I don't include it..

Any ideas how I can make this work?

29 Jun
3 weeks ago

fbc left a reply on How Do You Test If A Variable Is Numeric Or Not?

@CRONIX - I get the same error when trying to test for the existance of the variable. if (!$data[5]){ return view('errors.no-data'); } how would I do that without getting the error?

fbc left a reply on How Do You Test If A Variable Is Numeric Or Not?

@CRONIX - yup you are correct.. I uploaded the wrong file.. sorry for the bother, and thank you very much for your help!!

fbc left a reply on How Do You Test If A Variable Is Numeric Or Not?

@CRONIX - getting: "Undefined offset: 5" Error with this:

        if (($handle = fopen ( request()->file('file') , 'r' )) !== FALSE) {
            while ( ($data = fgetcsv ( $handle, 1000, ',' )) !== FALSE ) {
                $reading = new Utility_Meter_Readings ();
                $reading->property_id = $request->property_id;
                $reading->utility_id = $request->utility_id;
                $reading->resource_type = $request->resource_type;
                if(is_numeric($data [5])) {
                   //do nothing
                }
                else {
        //skip importing this record
        continue;
        }
                    $date = date_create($data [3]);
                $reading->time = date_format($date, 'U');
                $reading->kwh = $data [5];
                $reading->save ();
            }
            fclose ( $handle );
        }

fbc started a new conversation How Do You Test If A Variable Is Numeric Or Not?

I just finish creating a CSV upload function and am pretty happy with it, but feel it could be improved.. I would like to have it skip the header or basically any row where $data [5] is not numeric. I think a CONTINUE will do the trick, but I need to know how to test if a variable is numeric in value or not.

I used this code:

        if (($handle = fopen ( request()->file('file') , 'r' )) !== FALSE) {
            while ( ($data = fgetcsv ( $handle, 1000, ',' )) !== FALSE ) {
                $reading = new Utility_Meter_Readings ();
                $reading->property_id = $request->property_id;
                $reading->utility_id = $request->utility_id;
                $reading->resource_type = $request->resource_type;
//                if($data [5] ??) {
//                    continue;
//                }
                $date = date_create($data [3]);
                $reading->time = date_format($date, 'U');
                $reading->kwh = $data [5];
                $reading->save ();
            }
            fclose ( $handle );
        }

I got it here: https://justlaravel.com/import-csv-data-store-database/

It seems to be more corePHP than Laravel. So how do I test if a variable has a numeric value?

05 Jun
1 month ago

fbc left a reply on Carbon Timestamp Support For Millisecond Epoch???

@MSOVANI - "Call to undefined method Carbon\Carbon::getPreciseTimestamp()"

How do I update my carbon version without updating my whole laravel?

fbc left a reply on ERROR - Call To A Member Function Pluck() On Array - Help

@TRAY2 - Thanks!!! With some modification(for my understanding) I think that will work:

            /* Extract times to array and apply time offset */
            $result = [];
            foreach($latestrtfeed as $record) {
                $record[0] = Carbon::createFromTimestamp($record[0])->modify('-6 hours')->getTimestamp();
                $result[] = date('H:i', $record[0]);
            }
            dd($result);

fbc left a reply on ERROR - Call To A Member Function Pluck() On Array - Help

@Cronix could you lend a hand? You always seem to get exactly what i'm trying to do.

fbc left a reply on ERROR - Call To A Member Function Pluck() On Array - Help

@tray2 @johnbraun I previously tried inserting this after pulling the feed but it changed the first record ID and not the data label itself:

            /* Rename the 0 key to time in the array */
//            $latestrtfeed['time'] = $latestrtfeed[0];
//            unset($latestrtfeed[0]);

fbc left a reply on ERROR - Call To A Member Function Pluck() On Array - Help

@TRAY2 - the source is this:

array:145 [▼
  144 => array:2 [▼
    0 => 1559739600000
    1 => 39103.5828125
  ]
  143 => array:2 [▼
    0 => 1559739000000
    1 => 39102.619270833
  ]
  142 => array:2 [▼
    0 => 1559738400000
    1 => 39101.740234375
  ]
...

the result is this:

array:145 [▼
  144 => array:1 [▼
    0 => 17:00
  ]
  143 => array:1 [▼
    0 => 16:59
  ]
  142 => array:1 [▼
    0 => 16:58
  ]
...

fbc left a reply on ERROR - Call To A Member Function Pluck() On Array - Help

@johnbraun @tray2

OK I revised and solved the plucking problem with Arr:pluck() helper.. however the map function as predicted because of not being able to pass $0

I'm trying to endup with an array I can pass to highcharts as labels to a graph.

No one wants to see EPOCH right???

so the whole thing will endup looking like this:

            /* Pull the Feed */
            $latestrtfeed = json_decode(file_get_contents(
                'http://xxx.xx/feed/data.json?id=' . $rtdevice[0]->feed_id . '&start='.$startDay.'000&end='.$endDay.'000&interval=600&apikey=xxxx'
            ), true);

            /* Reverse the Feed so the labels and data show up from left to right in graph*/
            $reversedrtfeed = collect($latestrtfeed)->sortByDesc('0')->all();


            /* Pluck just the time fields to an array */
            $realtime_labels_array = Arr::pluck( $reversedrtfeed,'0')
                ->map(function ($time) {
                    /* Add the Time offset */
                    return Carbon::createFromTimestamp($time)->modify('-6 hours')->getTimestamp();
                })
                ->toArray();

            /* change the array time format to Hours and seconds */
            $formattedDates = array_map(function ($time) {
                return date("H:i", $time);
            }, $realtime_labels_array);
...
            /* pass the formatted labels to Highcharts*/
            $realtime_consumption_chart->labels($formattedDates);
...

fbc started a new conversation ERROR - Call To A Member Function Pluck() On Array - Help

I'm trying to pluck() a column called '0' from an array and getting the error.

the array stored in $reversedrtfeed looks like this:

array:145 [▼
  144 => array:2 [▼
    0 => 1559739600000
    1 => 39103.5828125
  ]
  143 => array:2 [▼
    0 => 1559739000000
    1 => 39102.619270833
  ]
  142 => array:2 [▼
    0 => 1559738400000
    1 => 39101.740234375
  ]
...

and the how I'm trying to extract it is like this:

            /* Pluck just the time fields to an array */
            $realtime_labels_array = $reversedrtfeed->pluck('0')->map(function ($time) {
                /* Add the Time offset */
                return Carbon::createFromTimestamp($time)->modify('-6 hours')->getTimestamp();
            })->toArray();

once I fix this problem I assume I will have another one because I won't be able to pass a variable call $0 to the map function.. so I may have to pre-process the array to change the name of the label from '0' to 'time'

fbc started a new conversation Carbon Timestamp Support For Millisecond Epoch???

I've been digging around in the docs and the only thing I could find was something called ->valueOf() however it does not seem to work for me. I currently use this in my code:

        $startDay = Carbon::now()->subHours(24)->timestamp;
        $endDay = Carbon::now()->timestamp;

and find myself hard coding the three trailing 000's into the API URLs that require them. Like this:

 'http://xxx.xx/feed/data.json?id=' . $devices[0]->feed_id . '&start='.$startDay.'000&end='.$endDay.'000&interval=600&apikey=xxxx'

I rather not do that and use the right timestamp code that gives me milliseconds. Any ideas?

04 Jun
1 month ago

fbc started a new conversation Limiting Access To Users To A Certain Controller Using __construct Possible?

I know what I'm trying to do is not a long term solution and that I will need to properly create roles,etc,etc, however I just want to limit functions within a controller to be used by a certain user without having to go to each function and insert an IF statement testing for the right userid.

I currently have this:

    public function __construct()
    {
        $this->middleware('auth');
    }

I'm trying to do something like this:

    public function __construct()
    {
        $this->middleware('auth');
        if (Auth::user()->id != 1){
            // Hit the road jack - load auth error blade        
        }
    }
06 May
2 months 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
3 months 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
3 months 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
3 months 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
3 months 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
4 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
4 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
4 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
4 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
4 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?