kevbrn

Experience

29,070

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 269 Lessons Completed
  • 4 Favorites

26th July, 2018

kevbrn left a reply on Return Additional Columns From Polymorphic "pivot" Table? • 3 weeks ago

@staudenmeir yes, it did... I was looking in the wrong place for it.

18th July, 2018

kevbrn started a new conversation Return Additional Columns From Polymorphic "pivot" Table? • 1 month ago

I have a morphToMany()) relationship and I am storing additional data on the intermediate table for the relation... how can I retrieve that data? I tried withPivot('col_name) but that didn't return what I was looking for.

21st June, 2018

kevbrn left a reply on Extend Auth ResetsPassword Trait? • 1 month ago

Ah cool. Like the idea of using the PasswordReset event. Thank you, will give that a shot.

kevbrn started a new conversation Extend Auth ResetsPassword Trait? • 1 month ago

I'm looking for the best approach to update an additional field on the user model when someone resets their password without modifying the existing trait that Laravel uses to handle password resets. Basically when a user resets their password, the column 'password_changed_at' would get the current datetime as well.

Thanks!

27th April, 2018

kevbrn left a reply on Polymorphic Relationship With Where Clause • 3 months ago

Realized I was approaching this the wrong way and solved it in the controller.

 $project = Project::where('id', $id)->first();

        $logdata = IssuesLog::where('project_id', $id)       
        ->with(array('actions' =>  function ($query) use($id){
            $query->where('project_id', $id);
        }))
        ->get();

kevbrn started a new conversation Polymorphic Relationship With Where Clause • 3 months ago

I need to check for an additional value on a polymorphic relationship so in my model I am doing this

public function project()
    {

        return $this->hasOne(Project::class, 'id', 'project_id');

    }


public function actions()
    {
       
        return $this->morphOne(Actions::class, 'actionable')->where('project_id', '=', ????);

    }

But as specified by the ???? I'm not sure how to pass the project id value. I tried $this->project->id; which returns a project id but it just returns the first project id from the database. I also tried to reference the project() relationship on the model but it doesn't return any data. Not even sure this is possible so any help would be greatly appreciated.

Thanks! Kev

15th April, 2018

kevbrn left a reply on Child And $refs Not A Function • 4 months ago

Key part that I left out. The child component is created multiple times in a v-for so $refs needed to be indexed.

saveItem(index) {
    this.$refs.actionInput[index].saveData();
}

Inspect console and console.log() is your friend :)

kevbrn started a new conversation Child And $refs Not A Function • 4 months ago

So a pretty basic setup

Child component in the parent

<actions :item="item" @save="actionData" ref="actionInput"></actions>

The method in the child

methods: {
            saveData() {                
                console.log("fired");
            }
 },

I'm calling the saveData() method from the parent like so.

saveItem() {
                this.$refs.actionInput.saveData();
 },

but I get this error. Uncaught TypeError: this.$refs.actionInput.saveData is not a function

Any ideas?

Thanks!

kevbrn left a reply on Array Of Files Upload To S3 • 4 months ago

Anyone???

12th April, 2018

kevbrn left a reply on Access Property Via Relationship In Trait • 4 months ago

I figured it out. Its $this->actions->owner_id ... I was discarding that as the possible solution because PHPStorm was telling me that field actions could not be found in HandleActions. Doh!

kevbrn started a new conversation Access Property Via Relationship In Trait • 4 months ago

I have a trait ...

trait HandleActions
{

    public function assign($data)
    {

        if($data->action && !$this->actions()->exists())
        {

            $this->store($data);

        }elseif ($this->actions()->exists())
        {

            $this->modify($data);

        }

        return;

    }

    public function actions()
    {

        return $this->morphOne(Actions::class, 'actionable');

    }

    protected function store($data)
    {

        $action = $this->actions()->create([
            'project_id' => $data->project_id,
            'log_id' => $this->getLogID(),
            'log_item_id' => $data->id,
            'created_by' => auth()->user()->id,
            'action' => $data->action,
            'owner_id' => $data->owner_id,
            'due_date' => $data->due_date,
            'comments' => $data->comments
        ]);

        event(new NewActionCreated($action));

    }

    public function modify($data)
    {
       dd($this->actions()->owner_id);

        $this->actions()->update([
            'updated_by' => auth()->user()->id,
            'action' => $data->action,
            'owner_id' => $data->owner_id,
            'due_date' => $data->due_date,
            'comments' => $data->comments
        ]);

        $action = Actions::find($this->actions->id);

        if ($curr_owner <> $action->owner_id) {

            event(new ActionHasBeenReassigned($action));
        }

    }

    protected function getLogID()
    {

        $logid = Log::where('model', get_class($this))->pluck('id');

        return $logid[0];

    }

}

In the modify() method I need to compare the current value of actions()->owner_id to the value that is passed to the trait but I cannot access the property with $this->actions()->owner_id or the method I have on the actions model owner(). I get Undefined Property. Am I going about this the wrong way?

Thanks!

6th April, 2018

kevbrn started a new conversation Array Of Files Upload To S3 • 4 months ago

I'm looping over an array of files and wanting to store them in S3 but file() is a method on $request

foreach ($request->$files as $file) {

                $obj->files()->create([
                    'org_id' => session('org_id'),
                    'created_by' => auth()->user()->id,
                    'type' => $file->getMimeType(),
                    'filename' => $file->getClientOriginalName(),
                ]);

                $file->file('files')->storeAs($request->app, $file->filename,'s3');
            }

so I get Call to undefined method Symfony\Component\HttpFoundation\File\UploadedFile::file()

but even if the method were accessible file('files') is no longer valid either, correct?

Is there another method that handles storing an array of files? I looked through Illuminate\Http\UploadedFile but did not see anything.

Thanks!

1st April, 2018

kevbrn started a new conversation Return In Method Is Not, Returning Response In Render But Does In Console • 4 months ago

This method...

methods: {
            getDocs(projid, logid, file) {
                axios.get("/documents/download?project_id=" + projid + "&log_id=" + logid + "&filename=" + file)
                    .then(response => {
                        console.log(response.data);
                        return response.data;
                    });
            },

hits an endpoint that generates a tokenized URL to access a private file in S3. In the template I am iterating over the file reference stored in db and each iteration calls the method.

<div class="row" v-if="documents.length > 0">
    <h3 class="m-b-0 box-title">Current Files:</h3>
        <ul class="common-list">
            <li v-for="(doc, index) in documents" :key="doc.id" class="pointer">
                <a :href="getDocs(doc.project_id, doc.log_id, doc.actual_filename )">
                                        <i class="ti-file"></i> {{ doc.actual_filename }}
                                </a>
                          </li>
                 </ul>
</div>

When I console.log(response.data) I get exactly what I am looking to be returned.

https://www.screencast.com/t/kpLZoobjnbEn

However the return response.data; doesn't return anything, or any error?

Here is the structure of the returned response which is an http response from amazon.

https://www.screencast.com/t/F2BNSAGkm8d

Thanks!

31st March, 2018

kevbrn left a reply on Migrate Tries To Execute Already Migrated Migrations • 4 months ago

Thanks @topvillas and @Thyrosis

@Thyrosis - I'll give that a try. Anytime I need to recreate the app I would just export the db and re-import where needed but I agree keeping those files is ideal. Any ideas why they wouldn't get tracked in the first place?

Thanks!

kevbrn started a new conversation Migrate Tries To Execute Already Migrated Migrations • 4 months ago

That's a tongue twister... Occasionally when I run php artisan migrate' it attempts to run migrations that have already been executed thus throwing aBase table or view already exists`. To work around this I usually delete the offending migration but Id prefer to keep them around. How are migrations tracked? Does it just check against the migrations table?

kevbrn left a reply on Merge() Throws Call To Undefined Method • 4 months ago

Thanks @maslauskast

15th March, 2018

kevbrn left a reply on Merge() Throws Call To Undefined Method • 5 months ago

@maslauskast A single instance of Materialso that I can call the relationship methods against it, right? ... but yes, a single item of the Material or Activityinstance. Does that makes sense?

Is the only issue you see the lack of a check for null on $activity?

Thanks so much!

kevbrn left a reply on Merge() Throws Call To Undefined Method • 5 months ago

@maslauskast I came to that conclusion as well. Thank you! I changed it to

 foreach ($data->selected_skus as $skus) {

            $material = Material::where('sku', $skus)->get();

            if(!$material->isEmpty()) {

                $product->materials()->syncWithoutDetaching([$material[0]->id => ['qty' => $skus['qty']]]);

            }else{

                $activity = Activity::where('sku', $skus)->get();

                $product->activities()->syncWithoutDetaching([$activity[0]->id => ['qty' => $skus['qty']]]);
            }

        }

$materialshould return a single instance of the collection. I was trying to then add the value of $skus['qty'] to the collection to be inserted.

This works but I'm not sure I like $material[0]

thanks again so very much!

kevbrn left a reply on Merge() Throws Call To Undefined Method • 5 months ago

changed to get() But now I get "Call to a member function getKey() on string"

kevbrn left a reply on Merge() Throws Call To Undefined Method • 5 months ago

Doh!! Thank you @maslauskast ... I get caught out on that all the time.

kevbrn started a new conversation Merge() Throws Call To Undefined Method • 5 months ago

Getting undefined method on merge() and not quite sure why?

foreach ($data->selected_skus as $skus) {

            $material = Material::where('sku', $skus)->first();

            if($material) {               

                $updatedMat = $material->merge([
                    'qty' => $skus['qty'],
                ]);             

                $product->materials()->syncWithoutDetaching([$updatedMat->id => ['qty' => $updatedMat->qty]]);

....

I have verified via dd() that $material is returning the appropriate collection.

works fine on $request and according to the docs merge() works on collections.

https://laravel.com/docs/5.5/collections#method-merge

I'm sure I am just using it incorrectly.

Much appreciated!

KB

10th March, 2018

kevbrn left a reply on Conditional Vue Component In Blade • 5 months ago

@Drfraker thanks, that's pretty much how I have it set up at the moment but seeing as an individual component can (and in the case of my app) make up 100% of the rendered content why keep making blade files? Thinking it would be similar to an SPA maybe?

kevbrn started a new conversation Conditional Vue Component In Blade • 5 months ago

What would be the "right" way to accomplish the following.

render a vuejs component in blade depending on the url?

@if(some url string)
    <component-one></component-one>
@elseif(some other url string)
    <component-two></component-two>

....

or with vue-router maybe? or vue dynamic components?

Just looking for the more correct way to go about this.

Thanks, Kevin

18th February, 2018

kevbrn left a reply on Pass Data To Child Component With`@click` • 6 months ago

Hmm ok. That passes the "clicked" data but I can't assign it to any properties.

item is an object.

props: ['item],

data() {
    return{
        item_id: this.item.id
    }
},

Results in item_id being undefined which I assume is because item has no value until the @click but shouldn't it be reactive and assume the value after the click?

kevbrn left a reply on Pass Data To Child Component With`@click` • 6 months ago

Thanks @topvillas ... that's how I imagined it in my head... let me give that a try.

kevbrn started a new conversation Pass Data To Child Component With`@click` • 6 months ago

Is this possible? I understand you can pass data from a parent component to a child component via props, but what if I want the data in the props to be based on user interaction, @click? Is there a specific method for doing such a thing?

6th February, 2018

kevbrn left a reply on There Are No Commands Defined In The "command" Namespace. • 6 months ago

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\ClearTasksFromNotifications::class,
        Commands\ClearNotificationsTable::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
         $schedule->command('command:ClearNotificationsTable')
             ->weekly()->mondays()->at('08:00');
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

kevbrn left a reply on There Are No Commands Defined In The "command" Namespace. • 6 months ago

@tykus No they do not. Which is odd.

@mfoote I believe I did it as

php artisan make:command ClearNotificationsTable

They are located in App\Console\Commands

kevbrn left a reply on There Are No Commands Defined In The "command" Namespace. • 6 months ago

Ya that's what I am doing.

php artisan command:ClearNotificationsTable

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class ClearNotificationsTable extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:ClearNotificationsTable';

kevbrn started a new conversation There Are No Commands Defined In The "command" Namespace. • 6 months ago

I have created some commands in my application and I registered them in Console/Commands/Kernel.php

 protected $commands = [
        Commands\ClearNotificationsTable::class,
        Commands\ClearTasksFromNotifications::class,       
    ];

Yes when I try to execute them via artisan php artisan command:ClearNotificationsTable I get the following error.

"There are no commands defined in the "command" namespace."

The command files are all located in Console/Commands

Any ideas?

25th January, 2018

kevbrn left a reply on Vue Wont Render Table • 6 months ago

Was able to resolve by downgrading node.js to v6.11.5

kevbrn started a new conversation Vue Wont Render Table • 6 months ago

Ok this is a bizarre one. I've been working on this app for a while and have vue components throughout the app that work perfectly. I get a new computer, move all my utilities and projects to the new computer and get back to work. I'm attempting to add a new vue component so I start building out the vue file and it will not render a simple table if it has a in it... The file doesn't have any JavaScript in it yet, nothing but html and it just will not load. It compiles without errors but as soon as I load it in the browser I get the following.

'Uncaught SyntaxError: Unexpected token )'

the error line from app.js via sources in chrome console

/******/ ]);"td"), <--- this ')' right here
                _vm._v(" "),
                _c("td"),
                _vm._v(" "),
                _c("td"),
                _vm._v(" "),
                _c("td"),
                _vm._v(" "),
                _c("td"),
                _vm._v(" "),
                _c("td"),
                _vm._v(" "),
                _c("td"),
                _vm._v(" "),
                _c("td")
              ])
            ])
          ]
        )
      ])
    ])
  }
]

Here is the vue file itself.


<template>
    <div id="rfi-log-root">
        <div class="table-responsive">
            <table id="myTable"
                   class="tablesaw table-striped table-hover table-bordered table color-table dark-table"
                   data-tablesaw-mode="columntoggle" data-tablesaw-minimap>
                <thead>
                <tr>
                    <th>Unique ID</th>
                    <th>ID</th>
                    <th>Question</th>
                    <th>Requester Name</th>
                    <th>Request Date</th>
                    <th>Response</th>
                    <th>Response Date</th>
                    <th>Documents</th>
                    <th>Unresolved/Closed</th>
                </tr>
                </thead>
                <tfoot>
                <tr>
                    <th>Unique ID</th>
                    <th>ID</th>
                    <th>Question</th>
                    <th>Requester Name</th>
                    <th>Request Date</th>
                    <th>Response</th>
                    <th>Response Date</th>
                    <th>Documents</th>
                    <th>Unresolved/Closed</th>
                </tr>
                </tfoot>
                <tbody>
               <tr>
                   <td></td>
                   <td></td>
                   <td></td>
                   <td></td>
                   <td></td>
                   <td></td>
                   <td></td>
                   <td></td>
                   <td></td>
               </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>


<script>

    export default {
        data() {
            return {

            }
        }
    }

</script>

If I remove the all of the <tr><td> from <tbody> it renders without error. I'm so confused by this one and its roadblocked my progress on all the work I need to get done.

The new computer that I'm developing on is Windows 10. The old one was Windows 8. When I installed PHPStorm on the new computer I exported all of the setting from my old computer and I just have no idea what the deal is here.

Thanks!

16th January, 2018

kevbrn left a reply on Push Response To Table • 7 months ago

ya.. just copied in paste from the console didn't maintain formatting.

kevbrn started a new conversation Push Response To Table • 7 months ago

Table is populated from data prop (from Laravel)

<tr v-for="(sku_sub_type, index) in skusubtypes" :key="sku_sub_type.id">
    <td>{{ sku_sub_type.sku_sub_type }}</td>
        <td style="text-align:center">{{ sku_sub_type.sku_type.sku_type }}</td>
        <td style="text-align:center"><i class="icon-pencil"></i></td>
        <td style="text-align:center"><i class="text-danger ti-close"></i></td>
</tr>

User has the ability to add a new item to the database and the new values are push into this skusubtypes

methods: {
            saveItem() {
                let that = this;
                this.loading = true;
                this.form.post('...', this.form)
                    .then(response => {
                        that.loading = false;
                        console.log(response);
                        this.skusubtypes.push(response);
                    })
                //.catch(error => this.errors.record(error.response.errors));
            }
        },

via the console.log I can see that the response contains the correct object,

however this line ...

<td style="text-align:center">{{ sku_sub_type.sku_type.sku_type }}</td>

generates the error "app.js:3423 [Vue warn]: Error in render: TypeError: Cannot read property 'sku_type' of undefined"

this is what is sent back from the axios.post in the response

created_at : "2018-01-16 16:32:29" created_by : 1 id : 2 org_id : 1 sku_sub_type : "Nike Red" sku_type : Object created_at : "2018-01-13 20:00:11" created_by : 1 id : 2 org_id : 1 prod_level : 1 sku_type : "Leather" updated_at : "2018-01-13 20:00:11"

15th January, 2018

kevbrn left a reply on Map() Not A Function • 7 months ago

Found the issue. All my fault. Had not updated the related controller in prod and was getting an object{} instead of an array[]

kevbrn started a new conversation Map() Not A Function • 7 months ago

This computed property works perfectly on my local dev server (artisan serve), but when I pushed it to my production server (Ubuntu/Apache) it generates this error

[Vue warn]: Error in render: "TypeError: this.logitems.map is not a function"

computed: {
            daysUntilDue: function () {
                return this.logitems.map(function (logitem) {
                    let b = logitem.plan_complete_date;
                    return moment(b).fromNow();
                });
            },

logitems is data from laravel via a [props]

any ideas?

Im guessing its some difference with the environment but I have no idea what it could be.

Thanks!

10th January, 2018

kevbrn left a reply on Accessing Dynamic Arrays • 7 months ago

Thanks again @kreierson that was the answer. Worked perfectly.

kevbrn left a reply on Accessing Dynamic Arrays • 7 months ago

Ah ok. That makes sense. Let me see if I can make that happen. Thanks @kreierson

kevbrn started a new conversation Accessing Dynamic Arrays • 7 months ago

A section of my form contains a table of contacts. Clicking a button adds a new row to the table so that more contacts can be added. How do I access the values of these added rows (dynamic array(?) when posting the form.

I am posting the form via a form class like so...

 data() {
            return {
                contact_rows: [
                    {fname: '', lname: '', title: '', phone: '', email: ''}
                ],
                form: new Form({
                    vendor_name: '',
                    vendor_admin: '',
                    primary_phone: '',
                    url: '',
                    nickname: '',
                    address_line1: '',
                    address_line2: '',
                    city: '',
                    state_id: [],
                    zip_code: '',
                    contacts: [
                        { fname: this.contact_rows ??? }
                    ]
                }),
                states: [],
            }
        },

Here is how it looks in vue console.

https://www.screencast.com/t/cVFtclSMs

So in contacts: [] and not quite sure how to set these values from the inputs.

6th January, 2018

kevbrn left a reply on Access Array Inside Collection? • 7 months ago

Thanks @calder12 and @sheldonscott

Much Appreciated!

ended up with

$notification = $user->notifications[0]->data['action_id'];

kevbrn started a new conversation Access Array Inside Collection? • 7 months ago

How would I access [data] inside of this collection?

I specifically need to access action_id

{
"id": "BEA9A924-C7C5-4B29-B19B-A4341AABD434",
"type": "App\Notifications\ActionIsPastDue",
"notifiable_id": "73",
"notifiable_type": "App\User",
"data": {
    "action_id": 206,
    "days_late": 23,
    "message": "*REI and VDC DEC teams to...",
    "link": "/logs/actions/my-actions/206"
},
"read_at": null,
"created_at": "2018-01-06 13:14:28.673",
"updated_at": "2018-01-06 13:14:28.673"
}

I have tried...

$notification = $user->notifications->filter(function ($notification) use ($id) {
                return $notification->data->action_id == $id;
            });

and ...


$notification = $user->notifications->data->where('action_id', $id);

but Property [data] does not exist on this collection instance. .Same error when I try it with action_id.

3rd January, 2018

kevbrn left a reply on $emit From Form Class • 7 months ago

Ya, I tried that. I think that since the form class is instantiated in a vue instance... eg.

 export default {
        data() {
            return {
                permissions: [],
                form: new Form({
                    name: '',
                    sel_permissions: []
                })
            }
        },

and not a vue instance itself this.$emit is not available.

2nd January, 2018

kevbrn started a new conversation $emit From Form Class • 7 months ago

I'm using the form class from https://laracasts.com/series/learn-vue-2-step-by-step/episodes/29 and I was wondering how would you go about $emit an event from it or passing the response back to the calling method?

I tried

 onSuccess(data) {
        $emit('operation-complete', data);

        this.reset();
    }

within the class but the event does not fire. If I put the $emit in the method that calls the this.form.post data is undefined.

Thanks!

24th December, 2017

kevbrn left a reply on Axios 404 In Different Environment • 7 months ago

Removed axios from the equation and replaced with a standard form post/patch and it works perfectly.

kevbrn left a reply on Axios 404 In Different Environment • 7 months ago

Ya good point. The app is "fine" essentially. I will look into any axios/IIS related issues.

Thanks @Snapey really appreciate the input. If I find a solution, Ill post back.

kevbrn left a reply on Axios 404 In Different Environment • 7 months ago

It appears to be coming from IIS. I have the rewrite for IIS module installed. I will check it out and see if anything seems incorrect there.

kevbrn left a reply on Axios 404 In Different Environment • 7 months ago

No I use the artisan serve, server

kevbrn left a reply on Axios 404 In Different Environment • 7 months ago

Ah, gotcha

kevbrn left a reply on Axios 404 In Different Environment • 7 months ago

just meaning that when you hit http://domain.com you get the root of the site. Its on IIS and I have the path for the site set to D:\Inetpub\root-folder\sitename\public

is not how it should be configured?

Edit Your Profile
Update

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