jgravois

Technical Manager at Universal Asset Management

Experience

85,675

2 Best Reply Awards

  • Member Since 3 Years Ago
  • 928 Lessons Completed
  • 18 Favorites

9th November, 2017

jgravois started a new conversation Filtering With A Dynamic Key Problems • 2 weeks ago

I have an array of objects looking like this

{
    clerical: false,
    is_available: true,
    management: false,
    quality: false,
    receiving: true,
    user_id: 4,
    username: John Brown
}

I am trying to create a computer property to filter only if "is_available" is true and if the type (passed in as a prop) is also true

workers() {
                if(this.staff) {
                    return _.filter(this.staff, function(s) {
                        return s.is_available == true && s[this.typer] == true;
                    });
                } // end if
            }

the above code give me an "error during evaluation" in Vuex I am instantiating the component as such <task-type :typer_id="type.id" :typer="type.type"></task-type> and accepting the props ... i.e., typer might equal "management"

7th November, 2017

jgravois started a new conversation Using Api Resources In A View Composer • 2 weeks ago

I am trying to use an API Resource (Laravel 5.5 Transformer kinda) in a View Composer and receive a ’htmlspecialchars() expects parameter 1 to be string, object given” for my troubles.

view()->composer('*', function ($view) {
      $view->with('curUsr', new UserResource(User::find(auth()->id())));
 });

… any ideas on how to do this?

26th October, 2017

jgravois left a reply on Pusher And The Queue Listener • 4 weeks ago

Could I use a cron job running every five minutes with this

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class CheckQueue extends Command
{
    protected $signature = 'queue:checkup';

    protected $description = 'Ensure that the queue listener is running.';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $this->call('queue:restart');
        $this->comment('Queue listener is running.');
    }
}

jgravois left a reply on Pusher And The Queue Listener • 4 weeks ago

Thanks for the link.

Looks like I could use Forge and let it take care of Digital Ocean ... what about Laravel Valet ... I literally just spent 35 minutes looking for a bug until my co-worker reminded me the code is working and the tests prove it ... you queue is off.

jgravois started a new conversation Pusher And The Queue Listener • 4 weeks ago

I am using Pusher for the first time to power a 24/7 operations app and everything is working great EXCEPT the Queue Listener stops randomly both in Laravel Valet (where I am building the app) and on the Digital Ocean server.

  1. Is there a command that can be run to determine if the Queue is running?
  2. How do others using Pusher deal with Premature Queue Death?

thanks!!

25th October, 2017

jgravois started a new conversation Watcher Works But Fails • 4 weeks ago

I need to time multiple users on a task so I set a value in the Vuex Store to increment whenever a user starts his/her timer and decrement when he/she pauses the timer. If the value = 1, the task timer should start and if the value = 0, the task timer should pause. If I start a single user and pause them, the Watcher works perfectly. However, if I start more than one user, when I pause the last one, the task timer doesn’t pause. Any Ideas??? Here’s my Watcher:

watch: {
            timers_started(newVal) {
                if(newVal === 1) {
                    this.startTimer();
                } else if(newVal === 0) {
                    this.pauseTimer();
                } // end if
            }
        },

10th October, 2017

jgravois started a new conversation Environment Variables In The Vue.js Front End • 1 month ago

I am trying to post authentication credentials as follows

signin() {
    let path = process.env.APP_PATH + 'api/remote/authenticate';
    axios.post(path, {email: this.email, password: this.password},
                               {headers: {'X-Requested-With': 'XMLHttpRequest'}})
    .then(
        (rsp) => {
            //console.log('Storing Token', rsp);
                localStorage.setItem('token', rsp.data.token);
                this.$emit('token_stored');
        }) 
.catch(
       (error) => console.log(error)
);
               

My dev.env.js file

var merge = require('webpack-merge');
var prodEnv = require('./prod.env');

module.exports = merge(prodEnv, {
    NODE_ENV: '"development"',
    APP_PATH: '"https://www.teamsite.dev/"'
});

My prod.env.js file

module.exports = {
    NODE_ENV: '"production"',
    APP_PATH: '"https://www.corporate.com/"'
};

However, I am getting

POST http://localhost:8080/undefinedapi/remote/authenticate 404 (Not Found)

This is my first attempt with vue-cli, so please, be gentle.

Thanks

1st October, 2017

jgravois started a new conversation Array Field Not Updated When Returned From Static Method • 1 month ago

In this snippet, $staffing is not holding the value it calculates in this method when returned. Am I missing something?

public static function makePhaseOneTasks($scope, $staffing)
    {
        if(!$scope['asset_arrival_date']) { return false; } // end if

        $reporter = [];
        $today = Carbon::today();
        $asset_arrival = Carbon::createFromFormat('Y-m-d', $scope['asset_arrival_date']);
        $arrival = ($scope['asset_arrival_date'] ? $asset_arrival->addHours(8) : null);
        $prearrival = ($arrival ? $arrival->subDays(3) : null);
        $dt = ($today->gt($prearrival) ? $today : $prearrival);
        $mins = 0;

        $tasks = AdcWorkscopeTask::where('phase_id', 1)
            ->where('is_completed', false)
            ->get();

        foreach($tasks as $task) {
            $dt = $dt->addMinutes($mins);
            $reporter[] = $task->description;

            //TODO - Check Availability
            foreach($task->equipment as $equip) {
                $eq = WsEquipment::whereId($equip->id)->first();
                if($eq && $dt) {
                    $newbie = $eq->assign($task, $dt->format('Y-m-d H:i'), $task->time_allotted);
                    $reporter[] = $newbie;
                } // end if
            } // end foreach

            //TODO - Check Availability
            foreach($task->tooling as $tool) {
                $t = WsTooling::whereId($tool->id)->first();
                if($t && $dt) {
                    $newbie = $t->assign($task, $dt->format('Y-m-d H:i'), $task->time_allotted);
                    $reporter[] = $newbie;
                } // end if
            } // end foreach

            //TODO - Check Availability
        if(count($staffing[$task->type_id]) >= $task->manning_min) {
                $staffers = collect($staffing[$task->type_id])
                    ->sortByDesc('daily7')
                    ->values();
                $staffing[$task->type_id] = $staffers;

             //TODO - FIX -- Deduct assigned minutes from staff so re-sorted above to assign equally
             for($t=0; $t<$task->manning_min; $t++) {
                    if($dt && $staffing[$task->type_id][$t]) {
                        $newbie = $staffing[$task->type_id][$t]
                            ->assign($task, $dt->format('Y-m-d H:i'), $task->time_allotted);
                        $staffing[$task->type_id][$t]->daily7 -= $task->time_allotted;
                        $reporter[] = $newbie;
                    } // end if
                } // end for
            } // end if

            $mins = $task->time_allotted;
        } // end foreach

        return [
            'progress' => $reporter,
            'mins' => $mins,
            'staffing' => $staffing
        ];
    } // end fn

24th September, 2017

jgravois left a reply on VM4028 App.js:14191 Uncaught ReferenceError: Vue Is Not Defined • 2 months ago

classic prestidigitation ... I NEVER thought to look in components.js

Thanks!

jgravois started a new conversation VM4028 App.js:14191 Uncaught ReferenceError: Vue Is Not Defined • 2 months ago

I can't get past this error and I think the code is correct. This is my app.js

import Vue from 'vue';
import axios from 'axios';
import Vuex from 'vuex';
Vue.use(Vuex);

import { store } from './vuex/store';

import './components';
import './filters';

axios.defaults.headers.common = {
    'X-CSRF-TOKEN': window.Laravel.csrfToken,
    'X-Requested-With': 'XMLHttpRequest'
};

const app = new Vue({
    el: '#app',
    store
});

22nd September, 2017

jgravois started a new conversation "Dynamic" Store Properties • 2 months ago

is there a way to create “dynamic properties” in a Vuex store? I have a task counter that I need to save state with across many components as well as many devices … there could be 1 or 100 active timers … so when I start a timers, I need something like timer_task20087 in the store … I don’t know how to programmatically add a property to the store.

14th September, 2017

jgravois left a reply on So Very, Very Lost In A Polymorphic Relationship • 2 months ago

never mind, the return in the call was screwing with the response

since the api to use will be

if($user->isAvailable('2017-09-15 08:00', 2880)) {
    $user->assign('2017-09-15 08:00', 2880);
}

this is PERFECT!

Thank you @martinbean and @36864

jgravois left a reply on So Very, Very Lost In A Polymorphic Relationship • 2 months ago

BTW, I am calling it like this

return $user->isAvailable('2017-09-15 08:00', 2880);

jgravois left a reply on So Very, Very Lost In A Polymorphic Relationship • 2 months ago

OK, I added this to the trait

public function isAvailable($date, $minutes)
    {
        $date = Carbon::createFromFormat('Y-m-d H:i', $date);
        $date_end = $date->copy()->addMinutes($minutes);
        return $this->assignments()
            ->orWhereBetween('assign_date', [$date, $date_end])
            ->orWhereBetween('assign_end_date', [$date, $date_end])
            ->exists();
    }

and I get

UnexpectedValueException in Response.php line 450: The Response content must be a string or object implementing __toString(), "boolean" given.

BUT I WANT AN EFFIN BOOLEAN .... arrggggg

jgravois left a reply on So Very, Very Lost In A Polymorphic Relationship • 2 months ago

BUT before I can do that ... I have to make sure that user and that forklift and that metal pallet are available during that time

jgravois left a reply on So Very, Very Lost In A Polymorphic Relationship • 2 months ago

LOL, don''t assume you misunderstood anything ... I am positive any ignorance is totally on my part.

Anyway, if I understand your question, the assignments table lists each (and is assigned via the assign method on the trait ... here is an example of use (still just testing but this works

foreach($tasks as $task) {
    if($task->id == 61) {
        $user->park('2017-09-14 08:00', 4320);
        $user->assign($task, '2017-09-20 08:00', 300);
        $lift->assign($task, '2017-09-20 08:00', 300);
        $pallet->assign($task, '2017-09-20 08:00', 300);
    } // end if
} // end foreach

jgravois left a reply on So Very, Very Lost In A Polymorphic Relationship • 2 months ago

I appreciate your time and ideas .... thanks!

The equipment and tooling is assigned just like staff ... it's not that the staff is using the equipment, the TASK is using the equipment. So, for example, removing the vertical stabilizer requires a rudder lock, 3 Level 4+ Techs and 2 other Techs (no level required - just hands and arms ... LOL)

So since equipment, tooling and staff are assigned in the same manner, wouldn't a polymorphic be the right tool?

jgravois left a reply on So Very, Very Lost In A Polymorphic Relationship • 2 months ago

That was where I began but as it became more complex, I reached for that polymorphic lesson.

There are TASKS that require TECHS of a certain skill level and possibly EQUIPMENT and TOOLING ... the TECHS have to be notified the morning of the TASK as well as have all their TASKS listed when they log in.

To me, it seemed that a polymorphic like Jeff described would all all tasks to be in a single table and would make later processing simpler.

jgravois started a new conversation So Very, Very Lost In A Polymorphic Relationship • 2 months ago

This is my very first attempt at a polymorphic relationship (I followed this lesson: [https://laracasts.com/series/how-do-i/episodes/8]) but I am quite lost.

I have users, equipment and tooling that can be “assigned” to a task so I created a trait for all three to inherit named Assignable.

I am trying to create an isAvailable() method that will return a boolean if the user, equipment or tooling is available during a specific period -- a call like return $user->isAvailable('2017-09-15 08:00', 2880); asking if a user can be assigned a task starting at 8:00 on 9/15 and lasting 2880 minutes. All I can seem to get is an exception of 'Object of class Illuminate\Database\Eloquent\Relations\MorphMany could not be converted to string'.

This is the schema of the table I am querying and the trait I created:

$table->increments('id');
$table->boolean('is_time_off')->default(false);
$table->boolean('was_notified')->default(false);
$table->integer('ws_task_id')->unsigned()->index();
$table->integer('assignable_id')->unsigned()->nullable();
$table->string('assignable_type')->nullable();
$table->dateTime('assign_date')->nullable();
$table->dateTime('assign_end_date')->nullable();
$table->timestamps();
<?php

namespace App\Traits;

use App\Models\AdcWorkscopeTask;
use App\Models\WsAssignedTask;
use Carbon\Carbon;

trait Assignable
{
    public function assignments()
    {
        return $this->morphMany(WsAssignedTask::class, 'assignable');
    } // end function

    public function scopeAssignedOn($query, AdcWorkscopeTask $task)
    {
        return $query->whereHas('assignments', function($query) use ($task) {
            $query->where('task_id', $task->id);
        });
    } // end function

    public function isAssignedOn(AdcWorkscopeTask $task)
    {
        return $this->assignments()->where('task_id', $task->id)->exists();
    } // end function

    public function isAvailable($date, $minutes)
    {
        //return $this->type;
        return $this->id;
    } // end function

    public function assign($task, $assignDate, $minutes)
    {
        $start_date = Carbon::createFromFormat('Y-m-d H:i', $assignDate);
        $end_date = $start_date->copy()->addMinutes($minutes);

        $this->assignments()->save(
            new WsAssignedTask([
                'ws_task_id' => $task->id,
                'is_time_off' => false,
                'was_notified' => false,
                'assign_date' => $start_date,
                'assign_end_date' => $end_date
            ])
        );
    } // end function

    public function park($assignDate, $minutes)
    {
        $start_date = Carbon::createFromFormat('Y-m-d H:i', $assignDate);
        $end_date = $start_date->copy()->addMinutes($minutes);

        $this->assignments()->save(
            new WsAssignedTask([
                'ws_task_id' => ' ',
                'is_time_off' => true,
                'was_notified' => false,
                'assign_date' => $start_date,
                'assign_end_date' => $end_date
            ])
        );
    } // end function
} // end trait

10th September, 2017

jgravois started a new conversation Submitting FormData Via Axios • 2 months ago

I am using vue-form-wizard for a large 5 panel form and the specs are that there are no “additional submit buttons” other than the wizard’s Next button … I have 4 of the 5 panels licked but the last panel is kicking my butt. It is a panel where 6 documents are uploaded. I wrapped just that panel in a form tag (the other panel submit via axios) like this:

<tab-content title="Documents" :before-change="docs_next">
      <form id="frmDocs" @submit.prevent="documentsUpload”>

docs_next is the method that this panel runs when the wizard’s next button is clicked

docs_next() { 
    document.getElementById('frmDocs').submit();
     return true;
 },
 documentsUpload() {
     alert('Form Submitting');
}

This is to test the submit and the alert is not firing. Any suggestions?

4th September, 2017

jgravois started a new conversation Dropdown Of Estimates Returns Null • 2 months ago

I need an array to create a dropdown where the values are like this

[ estimate: September 2017 ],
[ estimate: October 2017 ],
[ estimate: November 2017 ],
[ estimate: December 2017 ],
[ estimate: January 2018 ],
[ estimate: February 2018 ]

Always starting with current month and year and providing 5 additional options in mounted(), I have this.estimates = this.createEstimates(); and that method is

createEstimates() {
    let reporter = [];

     for(m=0; m<6; m++) {
         let newbie = {
             estimate: moment().add(m, 'months').format('MMMM YYYY')
         };
        reporter.push(newbie);
      } // end for
     return reporter;
}

however, this.estimates is null

2nd September, 2017

jgravois started a new conversation 'No Tests Found' Using Jest In New Laravel 5.5 Install • 2 months ago

I have a fresh install of Laravel 5.5.

I added the dependencies with

npm install --save-dev jest jest-vue-preprocessor babel-jest jsdom vue-server-renderer babel-preset-stage-2 bootstrap-sass

I added the normal snippets to package.json

"test": "./node_modules/.bin/jest"

and

"jest": {
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/babel-jest",
      ".*\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor"
    }
  }

I added a .babelrc file at the root containing

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-runtime"],
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": ["istanbul"]
    }
  }
}

I added a tests folder to /resources/assets/js and added a test

npm test returns the following and I don't know what to try

No tests found
In /Users/jgravois/code/laravel55
  155 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 0 matches
  testPathIgnorePatterns: /node_modules/ - 155 matches
Pattern: "" - 0 matches

26th August, 2017

jgravois started a new conversation OnChange Firing When Component Is Displayed Rather Than Changed ... Ugghhhh • 2 months ago

I have an @change on a dropdown and it is running when the component is displayed. Unfortunately there are over 400 companies so I have to endure 400 alerts … shouldn’t it only fire when the data is changed?

<div class="field">
    <div class="control">
        <div class="select">
            <select v-model="co.staff_id" @change="assign(co)">
                            <option value="">Please select...</option>
                <option :value="sp.id" v-for="sp in salesforce">
                    {{sp.name}}
                </option>
            </select>
        </div>
    </div>
</div>

and the method (for testing)

assign(obj) {
    alert('Change ' + obj.legal_name + ' to User Id ' + obj.staff_id);
}

21st August, 2017

jgravois started a new conversation Accessor Trying To Get Last Call -- BIG FAIL • 3 months ago

Given the follow relationship

public function calls()
    {
        return $this->hasMany(SalesCompanyTouch::class, 'company_id', 'id');
    } // end function

I need to get the latest record of this relationship so I have this accessor

public function getLastSaleContactAttribute()
    {
        $last_call = collect($this->calls());

        return $last_call->max('touch_date');
    } // end function

However it always returns null.

Any help is apprciated.

12th August, 2017

jgravois started a new conversation Struggling With Child/Parent Communication (in Vue.js That Is) • 3 months ago

I have a table and in each row there are icons for several trade references for each company. Clicking this icon pops up a modal. I really want to make the modal a child component since there is quite a bit of functionality.

<div class="modal" :class="{'is-active': showTraderModal}" @closeModal="toggleTradeModal">
    <tr-modal></tr-modal>
</div>

in the child component I have

toggleTradeModal() {  this.$emit('closeModal’); }

and in the parent

toggleTradeModal() {  this.showTraderModal = !this.showTraderModal; },

However, this never fires and the modal never closes. Is that not correct???

3rd August, 2017

jgravois started a new conversation Stopping The Base Table Already Exists Error After Package Install • 3 months ago

I installed a package yesterday that had its own migration and now when I try to add another migration, I am getting the Base Table already exists error. How can I resolve?

24th July, 2017

jgravois left a reply on Access A JQuery Variable Within A Vue.js Component • 4 months ago

props aren't an option but whether I load a hidden div with the value or store it as a global window object, I can't get the component to re-fetch new data ... meaning I assign to window.master_id and when I click the modal button, vue doesn't know to grab the fresh id ... I tried on created() and mounted() but apparently those are only triggered ONCE and not each time the modal is actually called. so, the first clicked modal is EMPTY and the 2nd, 3rd and 12,345th modal is always the data from the second-clicked row.

I am frustrated!!!!!

jgravois started a new conversation Access A JQuery Variable Within A Vue.js Component • 4 months ago

I have a huge dataset which I am paginating in blade. There is an edit button on each row to trigger an edit modal.

<button  type="link" 
               style="cursor: pointer;" 
               data-toggle="modal" 
               data-target="#editModal" 
               data-id="{{$master['id']}}">
      <i class="fa fa-pencil color-uam-blue"></i>
</button>

In jQuery I can grab the id

$(function() {
     $('#editModal').on("show.bs.modal", function (e) {
          let master_id = $(e.relatedTarget).data('id');
      });
});

The modal body is a custom vue component. My plan was to axios the single record and present an edit form.

I have tried to create a hidden div, fill its text attribute with the id and try to access it from there in the component -- FAIL! I have tried to stuff the id in localStorage and access it from vue there -- FAIL

I don't know what else to try to get the id into the component EACH TIME an edit button is clicked.

Any insight is GREATLY appreciated!!!

19th July, 2017

jgravois started a new conversation Pagination Woes: Losing The $masters->links() Functionality • 4 months ago

I need some pagination help … I have a table of 12,000+ records and without pagination, it is killing RAM. BUT I have to pass each through a transformer to process before loading and when I do the following I lose the $masters->link().

public function master_control()
    {
        $masters = [];
        $parts = EcoComponentMaster::where('description', '!=', 'DISCARDED')
            ->orderBy('model_value', 'desc')
            ->paginate(100);

        foreach($parts as $master) {
            $master = (new EcoComponentMastersTransformer)->transform($master);
            $masters[] = $master;
        } // end foreach

//        return $masters;

        return view('aeroeco.master_control', compact('masters'));
    } // end function

12th July, 2017

jgravois started a new conversation Trying To Grasp Parent-Child Communication • 4 months ago

I am emitting this from the child this.$emit('completed', this.index, rsp.data);

This is the reference in the parent

<single-part v-for="(part, idx) in parts"
            v-show="idx === cntPart"
            :single_part="part" :index="idx"
            @completed="completePart(i, p)"
></single-part>
                                        

The method in the parent

completePart(index, part) {
    alert('Emited index:' + index);
}

index is undefined

30th June, 2017

jgravois started a new conversation Vuex Initiation And Conditional Reload • 4 months ago

I am working on an application with HUGE datasets. I discovered VUEX and thought I could save users long waits so I added the store initialization to the navbar (since it is omnipresent throughout the app). The initial load time for the homepage jumped to 8 minutes.

I was also bothered by the fact that a user wanting to jump online just to reserve a company vehicle had to endure the loading of all of the modeling data ... just not right.

I have been looking all week for the correct way to load data to the store when needed and then used that data wherever appropriate. However, I can solve the means of determining IF the data is in the store or not and it hits the database again every time those pages are loaded.

If anyone has insights or a resource or an example of doing this correctly, I would greatly appreciate the sharing.

Thanks in advance!

20th June, 2017

jgravois started a new conversation Try-Catch Not Stopping CURL Error 60: SSL Certificate Problem: Invalid Certificate Chain Exception • 5 months ago

I am getting an exception in our uptime monitor that is breaking the monitor rather than returning a "false" to trigger a notification and a 'red light' in our dashboard.

I THOUGHT I would handle the exception with the code below but it is not working

public function fetch($path)
    {
        try {
            $response = $this->client->get($path, ['http_errors' => false]);
            return $response->getStatusCode();
        } catch (\GuzzleHttp\Exception\ConnectException $e) {
            Log::error('Received error: ' . $e->getMessage());
            return false;
        } catch (Exception $e) {
            Log::error('Received error: ' . $e->getMessage());
            return false;
        }
    } // end function

Any thoughts?

11th June, 2017

jgravois started a new conversation Laravel 5.4 Testing Using Transactions -- Wrong Database • 5 months ago

We have far too many migrations to use database migrations (because they really slow the testing down and then the developers don't test), so I am trying to move to use database transactions meaning moving from sqlite in :memory: to a sibling mysql database. However using the setup below, I am pulling from our production database rather than the new testing database.

#config/database.php

'mysql' => [
   'driver' => 'mysql',
   'host' => env('DB_HOST', '127.0.0.1'),
   'port' => env('DB_PORT', '3306'),
   'database' => env('DB_DATABASE', 'forge'),
   'username' => env('DB_USERNAME', 'root'),
   'password' => env('DB_PASSWORD', ''),
   'charset' => 'utf8mb4',
   'collation' => 'utf8mb4_unicode_ci',
   'prefix' => '',
   'strict' => true,
   'engine' => null,
 ],

 'mysql2' => [
     'driver' => 'mysql',
     'host' => env('DB2_HOST', '127.0.0.1'),
     'port' => env('DB2_PORT', '3306'),
     'database' => env('DB2_DATABASE', 'forge_test'),
     'username' => env('DB2_USERNAME', 'root'),
     'password' => env('DB2_PASSWORD', ''),
     'charset' => 'utf8mb4',
     'collation' => 'utf8mb4_unicode_ci',
     'prefix' => '',
     'strict' => true,
     'engine' => null,
  ],

#.env file

DB_CONNECTION=mysql
DB_HOST=--mask--
DB_PORT=3306
DB_DATABASE=--mask--
DB_USERNAME=--mask--
DB_PASSWORD=--mask--

#phpunit.xml

<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="mysql2"/>
<env name="DB_DATABASE" value="--mask--_test"/>

So to confirm, I modified the name field in the test database and ran this simple test

/** @test */
public function a_user_can_successfully_log_in()
{
        $this->disableExceptionHandling();
        $this->user = User::find(1);
        echo $this->user->name;

        $this->assertTrue(true);
}

and the output is definitely the version in the production DB

10th June, 2017

jgravois left a reply on A_guest_can_see_nothing_but_login • 5 months ago

@CodebyRay Thanks for the advice but, again, our developer/style guide dictates we apply it by constructor. That "guide" unfortunately was written by the VP of Technology whose only coding experience is with dot.net.nuke.

So, regardless of "a better way," I still need to develop a test that protects us from a repeat of my colleague's plunder.

jgravois left a reply on A_guest_can_see_nothing_but_login • 5 months ago

making progress ...

/** @test */
    function unauthenticated_users_may_not_see_anything_except_login()
    {
        $routeCollection = Route::getRoutes();

        foreach ($routeCollection as $value) {
            $value->withExceptionHandling()
                ->get($value->uri)
                ->assertRedirect('/login');
        }
    }

However, the test FAILS because "Call to undefined method Illuminate\Routing\Route::withExceptionHandling()"

jgravois left a reply on A_guest_can_see_nothing_but_login • 5 months ago

@Snapey excellent idea!!!

however, the execution of the idea may still be above my abilities.

I can't figure out how to loop through them. When I do the following, I get 0

$all_routes = Artisan::call('route:list');
echo $all_routes;

jgravois left a reply on A_guest_can_see_nothing_but_login • 5 months ago

@tjcasner We are using the auth middleware to separate guests from authenticated users and our developer/style guide dictates we apply it by constructor.

@Thyrosis if the colleague forgets to add the routes to the all routes array, we are in the same pickle.

My question was if there was a possible "wildcard" for ALL routes that could be used in testing to prevent a colleague from forgetting to add that in the constructor.

jgravois left a reply on A_guest_can_see_nothing_but_login • 5 months ago

we have run make:auth a while ago

jgravois started a new conversation A_guest_can_see_nothing_but_login • 5 months ago

In working on our Intranet, one of my colleagues forgot to include the auth middleware so for an entire week, we had exposed pages. Without authentication, only the login page should be accessible.

Is there a way to add a test that catches ALL ROUTES EXCEPT login and ensure a redirect? We have a large number of routes and I don't want my weekend to be about writing tests for EACH nor do we want such an omission as above to occur again.

Thanks in advance!

6th June, 2017

jgravois left a reply on Vue-Router Query Not Recognized • 5 months ago

I figured it out ... thanks!

jgravois started a new conversation Vue-Router Query Not Recognized • 5 months ago

I have a large listing of items each with an "expanded" attribute set to false by the model.

If ?id=## is not appended to the path, I need all collapsed -- works! if there is an ?id=##, I need to expand the corresponding row (so the executive know which on to approve (even though there is a filter provided)).

I added the following computed property but all rows remain collapsed

filtered_returns() {
                if(this.returns) {
                    if (this.search && this.search.length === 0) {
                        if(this.$route.query && this.$route.query != undefined) {
                            alert(this.$route.query.id);
                            _.each(this.returns, function(r) {
                                if(r.id == this.$route.query.id) {
                                    r.expanded = true;
                                } //end if
                            });
                            return this.returns;
                        } else {
                            return this.returns;
                        } // end if
                    } else {
                        return this.returns.filter((rma) => {
                            return rma.company_name.toLowerCase().indexOf(this.search.toLowerCase()) !== -1
                        });
                    } //end if
                } // end if
            }

29th May, 2017

jgravois left a reply on Vue 2.0 Filter To Show Elapsed Seconds As 00:00:00 Format • 5 months ago

oops ... 60 * 60 = 3600

jgravois started a new conversation Vue 2.0 Filter To Show Elapsed Seconds As 00:00:00 Format • 5 months ago

I am trying to create a filter for vue 2 that takes elapsed seconds and displays 00:00:00 (hours, mins and seconds). However, the value I am testing is 7200 (which should be 02:00:00) and it is displaying 20:00:00. Any fresh eyes to spot my mistake?

Vue.filter('timeInHours', function(value) {
    let hours =  parseInt(Math.floor(value / 360)); 
    let minutes = parseInt(Math.floor((value - (hours * 360)) / 60)); 
    let seconds= parseInt((value - ((hours * 360) + (minutes * 60))) % 60); 

    let dHours = (hours > 9 ? hours : '0' + hours);
    let dMins = (minutes > 9 ? minutes : '0' + minutes);
    let dSecs = (seconds > 9 ? seconds : '0' + seconds);

    return dHours + ":" + dMins + ":" + dSecs;
});

jgravois left a reply on Can Get Boolean But Can't Get Date From Collection • 5 months ago

@stanb thank you, that is exactly the code needed!

jgravois started a new conversation Can Get Boolean But Can't Get Date From Collection • 5 months ago

I have an indefinite list of certificates that a technician can use. I store them in a pivot table of techs and certs.

I am trying to create a certs attribute on the user. If I just try to return booleans, it works perfectly but if uncomment //$arrCerts[$award['slug']] = $fnd[0]->original['award_date']; and try to return the award date, I get this exception

ErrorException in Collection.php line 1456:
Undefined offset: 0

This is the method

public function getCertsAttribute()
    {
        $arrCerts = [];
        $certs = $this->certificates;

        $awards = EcoTechCertificate::all();

        foreach($awards as $award) {
            if($certs->contains('certificate_id', $award->id)) {
                $fnd = $certs->where('certificate_id', $award->id);
                $arrCerts[$award['slug']] = true;
                //$arrCerts[$award['slug']] = $fnd[0]->original['award_date'];
            } else {
                $arrCerts[$award['slug']] = false;
            } // end if
        } // end foreach

        return collect($arrCerts);
    } // end function

28th May, 2017

jgravois started a new conversation BelongsToMany Is Still A Mystery To Me • 5 months ago

I have a table of master components (eco_component_masters). The components in that table can be found on many different aircraft series (eco_ac_families) so I need a pivot table (eco_ac_component_families).

When I query the pivot table for a count, I get 681 records. This is that model

public function part_count($id)
    {
        return EcoAcComponentFamily::where('family_id', $id)->count();
    } // end function

If the user requests, I have to grab those components so I set up the this relationship in the EcoAcFamily model.

public function masters()
    {
        return $this->belongsToMany(EcoComponentMaster::class, 'eco_ac_component_families', 'component_id', 'family_id');
    } // end function

Now in the controller to return the master components related to a specific family, I have this method

public function parts_by_ata($id)
    {
        $family = EcoAcFamily::with('masters')->whereId($id)->first();

       return $family;
    } // end function

That method return TWO (2) master components not the 681 I expected.

Clearly I have yet to grasp the intricacies of the pivot despite watching all three videos on the subject. Any help is greatly appreciated.

27th May, 2017

jgravois left a reply on Update Nulling All Values In Database • 5 months ago

THANKS!

var_dump showed me what's wrong.

I did this and it works

public function update($id, Request $request)
{
        $data = (object) $request->json()->all();
        $project = AdcProject::whereId($id)->first();
    
    $project->contact->company = $data->contact['company'];
        $project->contact->firstname = $data->contact['firstname'];
        $project->contact->lastname = $data->contact['lastname'];
        $project->contact->title = $data->contact['title'];
        $project->contact->email = $data->contact['email'];
        $project->contact->save();

    $updated = AdcProject::whereId($id)->first();
    return $updated;
}

jgravois left a reply on Update Nulling All Values In Database • 5 months ago

"<script> Sfdump = window.Sfdump || (function (doc) { var refStyle = doc.createElement('style'), rxEsc = /([.*+?^${}()|\[\]\/\\])/g, idRx = /\bsf-dump-\d+-ref[012]\w+\b/, keyHint = 0 <= navigator.platform.toUpperCase().indexOf('MAC') ? 'Cmd' : 'Ctrl', addEventListener = function (e, n, cb) { e.addEventListener(n, cb, false); }; (doc.documentElement.firstElementChild || doc.documentElement.children[0]).appendChild(refStyle); if (!doc.addEventListener) { addEventListener = function (element, eventName, callback) { element.attachEvent('on' + eventName, function (e) { e.preventDefault = function () {e.returnValue = false;}; e.target = e.srcElement; callback(e); }); }; } function toggle(a, recursive) { var s = a.nextSibling || {}, oldClass = s.className, arrow, newClass; if ('sf-dump-compact' == oldClass) { arrow = '&#9660;'; newClass = 'sf-dump-expanded'; } else if ('sf-dump-expanded' == oldClass) { arrow = '&#9654;'; newClass = 'sf-dump-compact'; } else { return false; } a.lastChild.innerHTML = arrow; s.className = newClass; if (recursive) { try { a = s.querySelectorAll('.'+oldClass); for (s = 0; s < a.length; ++s) { if (a[s].className !== newClass) { a[s].className = newClass; a[s].previousSibling.lastChild.innerHTML = arrow; } } } catch (e) { } } return true; }; return function (root, x) { root = doc.getElementById(root); var indentRx = new RegExp('^('+(root.getAttribute('data-indent-pad') || ' ').replace(rxEsc, '\\$1')+')+', 'm'), options = {"maxDepth":1,"maxStringLength":160,"fileLinkFormat":false}, elt = root.getElementsByTagName('A'), len = elt.length, i = 0, s, h, t = []; while (i < len) t.push(elt[i++]); for (i in x) { options[i] = x[i]; } function a(e, f) { addEventListener(root, e, function (e) { if ('A' == e.target.tagName) { f(e.target, e); } else if ('A' == e.target.parentNode.tagName) { f(e.target.parentNode, e); } else if (e.target.nextElementSibling && 'A' == e.target.nextElementSibling.tagName) { f(e.target.nextElementSibling, e, true); } }); }; function isCtrlKey(e) { return e.ctrlKey || e.metaKey; } addEventListener(root, 'mouseover', function (e) { if ('' != refStyle.innerHTML) { refStyle.innerHTML = ''; } }); a('mouseover', function (a, e, c) { if (c) { e.target.style.cursor = "pointer"; } else if (a = idRx.exec(a.className)) { try { refStyle.innerHTML = 'pre.sf-dump .'+a[0]+'{background-color: #B729D9; color: #FFF !important; border-radius: 2px}'; } catch (e) { } } }); a('click', function (a, e, c) { if (/\bsf-dump-toggle\b/.test(a.className)) { e.preventDefault(); if (!toggle(a, isCtrlKey(e))) { var r = doc.getElementById(a.getAttribute('href').substr(1)), s = r.previousSibling, f = r.parentNode, t = a.parentNode; t.replaceChild(r, a); f.replaceChild(a, s); t.insertBefore(s, r); f = f.firstChild.nodeValue.match(indentRx); t = t.firstChild.nodeValue.match(indentRx); if (f && t && f[0] !== t[0]) { r.innerHTML = r.innerHTML.replace(new RegExp('^'+f[0].replace(rxEsc, '\\$1'), 'mg'), t[0]); } if ('sf-dump-compact' == r.className) { toggle(s, isCtrlKey(e)); } } if (c) { } else if (doc.getSelection) { try { doc.getSelection().removeAllRanges(); } catch (e) { doc.getSelection().empty(); } } else { doc.selection.empty(); } } else if (/\bsf-dump-str-toggle\b/.test(a.className)) { e.preventDefault(); e = a.parentNode.parentNode; e.className = e.className.replace(/sf-dump-str-(expand|collapse)/, a.parentNode.className); } }); elt = root.getElementsByTagName('SAMP'); len = elt.length; i = 0; while (i < len) t.push(elt[i++]); len = t.length; for (i = 0; i < len; ++i) { elt = t[i]; if ('SAMP' == elt.tagName) { elt.className = 'sf-dump-expanded'; a = elt.previousSibling || {}; if ('A' != a.tagName) { a = doc.createElement('A'); a.className = 'sf-dump-ref'; elt.parentNode.insertBefore(a, elt); } else { a.innerHTML += ' '; } a.title = (a.title ? a.title+'\n[' : '[')+keyHint+'+click] Expand all children'; a.innerHTML += '<span>&#9660;</span>'; a.className += ' sf-dump-toggle'; x = 1; if ('sf-dump' != elt.parentNode.className) { x += elt.parentNode.getAttribute('data-depth')/1; } elt.setAttribute('data-depth', x); if (x > options.maxDepth) { toggle(a); } } else if ('sf-dump-ref' == elt.className && (a = elt.getAttribute('href'))) { a = a.substr(1); elt.className += ' '+a; if (/[\[{]$/.test(elt.previousSibling.nodeValue)) { a = a != elt.nextSibling.id && doc.getElementById(a); try { s = a.nextSibling; elt.appendChild(a); s.parentNode.insertBefore(a, s); if (/^[@#]/.test(elt.innerHTML)) { elt.innerHTML += ' <span>&#9654;</span>'; } else { elt.innerHTML = '<span>&#9654;</span>'; elt.className = 'sf-dump-ref'; } elt.className += ' sf-dump-toggle'; } catch (e) { if ('&' == elt.innerHTML.charAt(0)) { elt.innerHTML = '&hellip;'; elt.className = 'sf-dump-ref'; } } } } } if (0 >= options.maxStringLength) { return; } try { elt = root.querySelectorAll('.sf-dump-str'); len = elt.length; i = 0; t = []; while (i < len) t.push(elt[i++]); len = t.length; for (i = 0; i < len; ++i) { elt = t[i]; s = elt.innerText || elt.textC…/span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>962</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>963</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>964</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>965</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>966</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>967</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>968</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>969</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>970</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>971</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>972</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>973</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>974</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>975</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>976</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>977</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>978</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>979</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>980</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>981</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>982</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>983</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>984</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>985</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>986</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>987</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>988</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>989</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>990</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>991</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>992</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>993</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>994</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>995</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>996</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>997</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>998</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>999</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1000</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1001</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1002</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1003</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1004</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1005</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1006</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1007</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1008</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1009</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵    <span class=sf-dump-index>1010</span> => <span class=sf-dump-note>array:18</span> [ &hellip;18]↵  </samp>]↵</samp>]↵</pre><script>Sfdump("sf-dump-1240214518")</script>

jgravois left a reply on Update Nulling All Values In Database • 5 months ago

not really sure

It is an axios patch from a vue component

jgravois started a new conversation Update Nulling All Values In Database • 5 months ago

I am patching a payload to an update method and I return request()->all() to see what's hitting the server.

The data looks like this:

data: Object
    contact: Object
        company: "blah"
        title: "blah
        firstname: "blah"
        lastname: "blah"
        email: "blah"

Since it is an object of objects, I am handing it as such

public function update($id)
{
        $project = Project::whereId($id)->first();

    $project->contact->company = request('contact->company');
        $project->contact->firstname = request('contact->firstname');
        $project->contact->lastname = request('contact->lastname');
        $project->contact->title = request('contact->title');
        $project->contact->email = request('contact->email');
        $project->contact->save();

    $updated = Project::whereId($id)->first();
        return $updated;

}

The data patched is not in the database but all fields are null;

Am I not handling the data properly?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.