fbc

fbc

Member Since 2 Years Ago

Experience Points
5,510
Total
Experience

4,490 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.

Level 2
5,510 XP
12 Sep
1 week ago

fbc left a reply on Convert All Fields X In Table To Integer

There are not column types in Mongo DB , yo can store whatever you'd like how you'd like it.

fbc left a reply on Convert All Fields X In Table To Integer

wouldn't it be better to just convert to integers all at once? Instead of having to mutate them all the time?? I corrected my STORE() function to:

$newrecord->units_consumed = (int)$request->units_consumed
$newrecord->save();

So that it saves in integer format...

fbc left a reply on Convert All Fields X In Table To Integer

yeah, they are numbers stored as strings, I'm trying to convert them back to numbers.

fbc started a new conversation Convert All Fields X In Table To Integer

I'm trying to write a script to convert a field in a MongoDB table to an integer. I tried something like this but it does not seem to do anything:

        $bills = BillingData::all();
        foreach ($bills as $bill)
        {
            $bill2 = BillingData::findOrFail($bill->_id);
            $converted = (int)$bill->units_consumed;
            $bill2->units_consumed = (int)$converted;
            $bill2->save();
        }

I get no errors but doesn't seem to do anything.

fbc left a reply on Database Intensive Queries Vs CPU Intensive Filtering?

OK Database it is. Thanks.

fbc started a new conversation Database Intensive Queries Vs CPU Intensive Filtering?

I was wondering what would be the most efficient way of arriving at the same answer? Here is what I'm using to query values for a chart and adding them to an array:

$daily_realtime_electrical_array = [];
$i=30;
while ($i >= 0){
$reading =  Utility_Meter_Readings::where('property_id', $property_id)->where('resource_type','1')
->where('time','>=',Carbon::now()->startOfDay()->subDay($i)->timestamp)
->where('time','<=',Carbon::now()->endOfDay()->subDay($i)->timestamp)
->pluck('kwh')->sum();
array_push($daily_realtime_electrical_array, $reading);

$i--;
}

should I just be querying the entire 30 days and running queries against that collection? However that would mean more memory to hold the entire collection would be required right?

11 Sep
1 week ago

fbc left a reply on Using Service Providers

Thank a bunch!!!! Wow!

fbc started a new conversation Using Service Providers

I need to share report creating functionality among my controllers. So I ran:

php artisan make:provider ReportServiceProvider

then I added:

use App\Providers\ReportServiceProvider;

to all the controllers I expected to use it in.

Then I tried various methods to call the functions but failed.

$forecast = ReportServiceProvider::class->get_dark_sky_weather($propdash->lat,$propdash->lng);
$forecast = app(ReportServiceProvider::class)->get_dark_sky_weather($propdash->lat,$propdash->lng);
$forecast = App::make(ReportServiceProvider::class)->get_dark_sky_weather($propdash->lat,$propdash->lng);

I used to use this:

$forecast = $this->get_dark_sky_weather($propdash->lat,$propdash->lng);

when the function was in the same controller. But since I've moved it to the Service Controller I can nolonger access it.

I've tried reading through the Laravel Documentation for Service Providers, but can't seem to make heads or tails of it. Any reference to a working example would be appreciated.

21 Aug
1 month ago

fbc left a reply on How To Change "06/01/2018 01" To Epoch Time?

@cronix @mabdullahsari Thanks alot guys!! I found my problem.. the time in the H column was in 12h and not in 24hr... I'm pretty sure that was what was causing my weird date and chart readings. Thanks.

fbc left a reply on How To Change "06/01/2018 01" To Epoch Time?

I ended up having to use this because several lines had blank spaces before the dates:

            $reading->time = Carbon::createFromFormat('d/m/Y H', ltrim($data[18]))->timestamp;

fbc left a reply on How To Change "06/01/2018 01" To Epoch Time?

something is not right, I'm getting times into 2021 maybe I should be using:

Carbon::createFromFormat('dd/mm/YYYY HH', $data[0])->timestamp

@mabdullahsari @Cronix

20 Aug
1 month ago

fbc left a reply on How To Change "06/01/2018 01" To Epoch Time?

yup gonna give that a try soon..thanks!!!!

fbc left a reply on How To Change "06/01/2018 01" To Epoch Time?

I need it. It displays the hour.

19 Aug
1 month ago

fbc started a new conversation How To Change "06/01/2018 01" To Epoch Time?

I am importing CSV data and the date/time field is formatted kinda weird and come in as:

06/01/2018 01
06/01/2018 02
06/01/2018 03
...

I would like to save this to a date field in a DB in Unix(Epoch)Time format.

Each ends up being $data[0] on the CSV import.

I tried something like:

                $date = date_create($data [0]);
                $reading->time = (int)date_format($date, 'U');

But it does not really work.

The last two digits are the hour. So this is hourly. I have CARBON installed if that is any help.

Thank you in advanced!

13 Aug
1 month ago

fbc left a reply on How Do You Filter Results From An Array Without Changing The Structure Of The Array?

It just means that it is an element that I should not use on my charts as it creates weird spikes. I just took care of it though.. I eliminated them at the extraction point.

        /* Pluck just the wattage values to an array */
        $realtime_data_array2 = [];
        foreach ($latestrtfeed['readMeter']['ReadSet']['0']['ReadData'] as $record) {
            /* Skip the bad ones */
            if ($record['Good'] == 0) {
                continue;
            }
            $realtime_data_array2[] = $record['kWh_Tot'];
        }

fbc started a new conversation How Do You Filter Results From An Array Without Changing The Structure Of The Array?

I query an API that gives me a results in an array like this: dd($latestrtfeed) give me:

array:1 [▼
  "readMeter" => array:2 [▼
    "Requested" => 1
    "ReadSet" => array:1 [▼
      0 => array:10 [▼
        "Meter" => "350002874"
        "Group" => 65244221
        "Interval" => 60
        "Protocol" => "v4"
        "MAC_Addr" => "xx:xx:xx:00:03:0a"
        "Tz_Offset_Sec" => 0
        "Bad_Reads" => 6
        "Good_Reads" => 994
        "Credits" => 1000000
        "ReadData" => array:1000 [▼
          0 => array:5 [▼
            "Good" => 1
            "Date" => "2019-08-13"
            "Time" => "21:28:04.778"
            "Time_Stamp_UTC_ms" => 1565731684778
            "kWh_Tot" => "8227.50"
          ]
...

the bad_reads throw my charts off.

So I need to filter all ['readMeter']['ReadSet']['0']['ReadData']['Good'] == 0 out of the array.

So I tried using the following query first, to copy all the GOOD reads into a new array but that did not work.

$latestrtfeed2 = $latestrtfeed->where(['readMeter']['ReadSet']['0']['ReadData']['Good'] == 1)->get();

then I tried the foreach below, but could not find the right command to make that happen.

        /* Copy good records to a new array */
        foreach ($latestrtfeed as $record) {
        /* Skip any records which are not good */
            if ($record['ReadSet']['0']['ReadData']['Good'] == 0) {
                continue;
            }
            /* Copy this record to new array */
            $latestrtfeedFiltered[] = $record;
        }

This example I think is the closest I have gotten but I end up with a "Undefined index: Good" error.

Any ideas would be helpful.

24 Jul
1 month ago

fbc left a reply on Automatic Sub-domain Creation/handling/routing With Apache Or NGINX

I think I found something that will allow me to write a function:

list($subdomain) = explode('.', Request::server('HTTP_HOST'))

then I could do something like:

$manufacturer = Manufacturer::where('subdomainslug', $subdomain[0])->first();
if (notempty($manufacturer)){
return view('view'.$manufacturer);
}

fbc started a new conversation Automatic Sub-domain Creation/handling/routing With Apache Or NGINX

I wanted to create landing pages on subdomains for every product Manufacturer, where only products from that specific manufacturer appears.

main domain = aaa.com & www.aaa.com

manufacturer1 = manufacturer1.aaa.com

manufacturer2 = manufacturer2.aaa.com

etc.etc.etc.

Is there a plugin that allows for this? How would I go setting something like that up? I would assume it will be a special route and Apache or NGINX config.

A google search resulted in packages that are more complicated than what I need, that will switch databases depending on the subdomain,etc.,etc. I just need something simple that says: If you are coming from a *.aaa.com route check for a record in the manufacturer table that matches the subdomain name and open X view file.

22 Jul
2 months 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
2 months 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
2 months 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&amp;ver=v4&amp;key=NjUyNDQyMjE6SzhNM1B3cnE&amp;format=json&amp;report=dy&amp;limit=100&amp;start_date=201907010000&amp;end_date=201908010000&amp;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:


[$gas2019consumption_array, $gas2018consumption_array, $gas2017consumption_array, $gas2016consumption_array] = $this->get_billing_gas_data($propertyid);

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 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
2 months 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
2 months 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 );
        }

wondering why $data [5] works fine outside of the if statement.

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
3 months 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 desired result is this:

array:145 [▼
  144 => array:1 [▼
    time => 17:00
  ]
  143 => array:1 [▼
    time => 16:59
  ]
  142 => array:1 [▼
    time => 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 failed 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);
...

how can I change the whole column called '0' to 'time' so I can manipulate it better?

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
3 months 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
4 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()) );

    }
12 Apr
5 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
5 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 animal. I'm not a Javascript proficient person, yet have used 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?