kevbrn

Experience

19,470

0 Best Reply Awards

  • Member Since 9 Months Ago
  • 188 Lessons Completed
  • 0 Favorites

12th December, 2017

kevbrn left a reply on Vue Template Not Rendering, No Errors • 1 hour ago

That did it! @bobbybouwmann thank you so much! I owe you big time :)

I did update this.items.splice(index, 1); to that.items.splice(index, 1); and once I did it worked as desired.

Huge thanks!

11th December, 2017

kevbrn left a reply on Vue Template Not Rendering, No Errors • 13 hours ago

So, after much trial an error this works... sort of.

methods: {
            del(index) {
                swal({
                    title: "Are you sure?",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Yes, delete it!",
                    closeOnConfirm: false
                }, function () {
                    swal({
                        title: "Deleted!",
                        type: "success"
                    }, function () {

                        //axios.delete('/admin/permissions/' + id);

                    });
                });
                this.items.splice(index, 1);
            }
        }

It was all in where I referred to this and the correct method apparently is splice(). While this does remove the item of the data its fires in the wrong place. Was hoping to have it fire after the axios delete, but at that point in the function this."anything" is undefined. May have to resort to a less complex confirmation method.

kevbrn left a reply on Vue Template Not Rendering, No Errors • 15 hours ago

@bobbybouwmann I've tried that one and all I get is Uncaught TypeError: Cannot read property 'slice' of undefined :(

10th December, 2017

kevbrn left a reply on Vue Template Not Rendering, No Errors • 1 day ago

@bobbybouwmann man you're a lifesaver, that works. However I had to pull the entire <table> into the vue template which I thought was odd. Before I did that it would render the <tr> outside of the table entirely.

anyway, that got me up and running... directly into my next brick wall. In this table I have a @click so that I can delete a row and its data.

like so...

<td style="text-align: center"><a href="#" id="sa-warning"><i
                        class="ti-close text-danger" @click="destroy(permission.id, index)"></i></a></td>

then a destroy method...

 methods: {
            destroy(id, index) {
                swal({
                    title: "Are you sure?",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Yes, delete it!",
                    closeOnConfirm: false
                }, function () {
                    swal({
                        title: "Deleted!",
                        type: "success"
                    }, function () {
                        //axios.delete('/admin/permissions/' + id);

                        alert(id + '' + index)

                        items.slice(index, 1)

                    });
                });
            }
        }

the alert() returns the correct id, and index but how can I now remove that item from the data so that it is no longer visible on the page without doing a post back?

Again thank you tremendously!

kevbrn started a new conversation Vue Template Not Rendering, No Errors • 2 days ago

As an inline template vue was rendering the expected table on the page. I've now moved it into its own component and nothing is being displayed in the browser. I can see the data in the vue console and there are no errors in chrome console but alas no content...

in view

    <table id="myTable" class="table table-striped">
                            <thead>
                            <tr>
                                <th>Name</th>
                                <th>Created At</th>
                                <th>Created By</th>
                                <th style="text-align: center">Edit</th>
                                <th style="text-align: center">Delete</th>
                            </tr>
                            </thead>
                            <permissions :data="{{ $permissions }}"></permissions>
       </table>

permissions.vue file ...

<template>
    <tbody>
        <tr v-for="permission in items">
            <td>{{ items.name }}</td>
        </tr>
    </tbody>
</template>

<script>
    export default {
        props: ['data'],

        data() {
            return {
                items: this.data
            }
        }
    }
</script>

app.js


Vue.component('flash', require('./components/Flash.vue'));
Vue.component('user', require('./components/User.vue'));
Vue.component('permissions', require('./components/Permissions.vue'));

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

Again no browser errors and no compile errors.

Assistance always appreciated!

Kevin

9th December, 2017

kevbrn left a reply on Undefined In V-for • 2 days ago

@robrogers3 Your response got me to the right place. I needed to not only pass the id in the method but also have the method accept the id. This works...

  methods: {
            destroy(id) {
              //axios.delete('/permissions/' + this.attributes.id);
                alert(id)
            }
        }
    }

Thank you so very much! Kevin

kevbrn left a reply on Undefined In V-for • 2 days ago

@robrogers3 you mean like so...

@click="destroy(attribute.id) ? I have tried that and I get the same error.

kevbrn started a new conversation Undefined In V-for • 2 days ago

I am following along in this video (https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/33?autoplay=true)

I am trying to delete an item from the database using the example from the video. I have my app setup pretty much the same except I'm rendering data in a v-for loop. When I click to call the "destroy" method, all I get is id is undefined...

in my view...

<permission :attributes="{{ $permissions }}" inline-template>
                            <table id="myTable" class="table table-striped">
                                <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Created At</th>
                                    <th>Created By</th>
                                    <th style="text-align: center">Edit</th>
                                    <th style="text-align: center">Delete</th>
                                </tr>
                                </thead>
                                <tbody>

                                    <tr v-for="(attribute in attributes" >
                                        <td>@{{ attribute.name }}</td>
                                        <td>@{{ attribute.created_at }}</td>
                                        <td>@{{ attribute.created_by }}</td>
                                        <td style="text-align: center" v-if="attribute.id == 1">
                                            <i class="ti-lock"></i>
                                        </td>
                                        <td style="text-align: center" v-else>
                                            <a><i class="icon-pencil"></i></a>
                                        </td>
                                        <td style="text-align: center" v-if="attribute.id == 1">
                                            <i class="ti-lock"></i>
                                        </td>
                                        <td  style="text-align: center" v-else><a href="#" @click="destroy"><i
                                                        class="ti-close text-danger"></i></a></td>
                                        </td>
                                    </tr>

                                </tbody>
                            </table>
                        </permission>

In my VUE component...

<script>
    export default {
        props: ['attributes'],

        data() {
            return {
                editing: false,
                body: this.attributes.body
            };
        },

        methods: {
            destroy() {
              //axios.delete('/permissions/' + this.attributes.id);
                alert(this.attributes.id)
            }
        }
    }

</script>

And all that is in the alert() is undefined. Any help is greatly appreciated.

Thanks, Kevin

22nd November, 2017

kevbrn left a reply on Access Global Scope Relationship? • 2 weeks ago

@snapey That works! So it is 'OK' to have that in my view or is there a more blade friendly approach?

Thank you so much!

kevbrn left a reply on Access Global Scope Relationship? • 2 weeks ago

Thanks @bobbybouwmann

Cant seem to get this to do what I need it to. Will have to come up with another approach.

kevbrn left a reply on Access Global Scope Relationship? • 2 weeks ago

I noticed that user_discipline is an array and not a collection? Is that right?

{  
   "id":210,
   "first_name":"Adam",
   "last_name":"XXXXX",
   "company_name":"XXXX",
   "app_role_id":"1",
   "project_id":null,
   "discipline_id":"22",
   "project_role_id":"76",
   "contact_id":null,
   "active_phases":null,
   "status":"1",
   "verified":"0",
   "email":"XXXXX",
   "cell_phone":"XXXX",
   "user_profile_pic":"nopic.png",
   "created_at":"2017-11-11 22:08:53.000",
   "updated_at":"2017-11-11 22:08:53.000",
   "is_admin":"0",
   "is_contact":"0",
   "pivot":{  
      "project_id":"1",
      "user_id":"210"
   },
   "user_discipline":[  
      {  
         "id":22,
         "name":"discipline_id",
         "value":"06. Structural",
         "created_at":null,
         "updated_at":null
      }
   ]
}

21st November, 2017

kevbrn left a reply on Access Global Scope Relationship? • 2 weeks ago

@Snapey ya that too

kevbrn left a reply on Access Global Scope Relationship? • 3 weeks ago

Thanks for the info guys. I implemented the check as suggested but its evaluating to NULL on every record, when in fact every record has data for the specified relationship. Its basically masking the "trying to get property of non-object error"?

@foreach($project->users as $user)
                                <tr>
                                    <td>{{ $user->first_name }}</td>
                                    <td>{{ $user->last_name }}</td>
                                    <td>{{ $user->company_name }}</td>
                                    <td>{{ $user->userDiscipline->value or '' }}</td>
                                    <td>{{ $user->email }}</td>
                                    <td>{{ $user->cell_phone }}
                                    </td>
                                </tr>
                            @endforeach 

20th November, 2017

kevbrn left a reply on Access Global Scope Relationship? • 3 weeks ago

Thanks @bobbybouwmann that still gives me the property of non-object error.

In my view I'm attempting to access it.

@foreach($project->users as $user)

                                <tr>
                                    <td>{{ $user->first_name }}</td>
                                    <td>{{ $user->last_name }}</td>
                                    <td>{{ $user->company_name }}</td>
                                    <td>{{ $user->userDiscipline->value }}</td>
                                    <td>{{ $user->email }}</td>
                                    <td>{{ $user->cell_phone }}
                                    </td>
                                </tr>
@endforeach 

if I output just $user->userDiscipline I get

[{"id":22,"name":"discipline_id","value":"06. Structural","created_at":null,"updated_at":null}]

Just need to access "value"

kevbrn started a new conversation Access Global Scope Relationship? • 3 weeks ago

I am returning this

{
"id": 1,
"ProjectName": "XXX",
"contact_id": "2",
"created_by": "1",
"status": "1",
"created_at": null,
"updated_at": null,
"users": [
{
"id": 1,
"first_name": "XXXX",
"last_name": "XXXX",
"company_name": "XXXX",
"app_role_id": "1",
"project_id": "1",
"discipline_id": "17",
"project_role_id": "1",
"contact_id": "1",
"active_phases": "1",
"status": "1",
"verified": "0",
"email": "XXXX",
"cell_phone": "XXXXX",
"user_profile_pic": "nopic.png",
"created_at": "2017-10-28 16:48:24.000",
"updated_at": "2017-11-17 01:44:39.000",
"is_admin": "1",
"is_contact": "1",
"pivot": {
"project_id": "1",
"user_id": "1"
},
"user_discipline": [
{
"id": 17,
"name": "discipline_id",
"value": "01. General",
"created_at": null,
"updated_at": null
}
]
},

Project has a relationship to User and User has a relationship to userDiscipline.

The query from the controller

    public function users(Project $project)
    {

        $project->load('users');

        return $project;

//        return view('projects.users', compact('project'));

    }

userDiscipline is a global scope query on the User model

    protected static function boot()
    {

        parent::boot(); 

        static::addGlobalScope('userDiscipline', function ($builder) {
            $builder->with('userDiscipline');
        });

    }

how do I access user_discipline:value ? doing $var->user_discipline->value gives Trying to get property of non-object.

Is this the correct approach? 'User' has several relationships that I need to return anytime the 'User' model is queried.

Thanks!

17th November, 2017

kevbrn left a reply on Missing Fields When Using Create() • 3 weeks ago

Thank you so much @thomaskim I will make changes right away.

kevbrn left a reply on Missing Fields When Using Create() • 3 weeks ago

That did in fact work @thomaskim thank you! In another controller, this works perfectly...

  public function store()
    {
        Assumptionverification::create(request(Input::all()));

        return back();
        //
    }

only difference is the model and controller.

kevbrn left a reply on Missing Fields When Using Create() • 3 weeks ago

Will give that a try @thomaskim but I have used that exact same syntax on another store operation and it works without issue.

kevbrn left a reply on Missing Fields When Using Create() • 3 weeks ago

Thanks vapenation, but still get the SQL error before dd() is executed?

kevbrn left a reply on Missing Fields When Using Create() • 3 weeks ago

I have $guarded = [];

kevbrn started a new conversation Missing Fields When Using Create() • 3 weeks ago

I have a form passing data to the store() method in my controller which contains

    public function store()
    {

        RiskLog::create(request(Input::all()));

        return back();
    }

I am "using" Illuminate\Support\Facades\Input;

and if I dd(Input::all()); all of the expected fields and values are being submitted to the method.

array:9 [▼
  "_token" => "MITY6DYyVeqNSunvOsXqhBbc05utYzNmj8SyaeOQ"
  "project_id" => "1"
  "company_id" => "1"
  "source_id" => "226"
  "discipline_id" => "19"
  "importance_level" => "4"
  "risk_name" => "TEST"
  "risk_description" => "TEST"
  "preventative_steps" => "TEST"
]

However, I get a SQL insert fails error message and based on the error it appears that the generated query doesn't contain any of the submitted data?

Cannot insert the value NULL into column 'source_id', table 'VDCEMT_UAT.dbo.risklogs'; column does not allow nulls. INSERT fails. (SQL: insert into [risklogs] ([updated_at], [created_at]) values (2017-11-17 15:53:54.000, 2017-11-17 15:53:54.000))

What am I missing?

16th November, 2017

kevbrn left a reply on UnionAll • 3 weeks ago

Thanks robroger

Ended up with this...

        $avByCompany =  AssumptionVerification::with('company')
            ->where('approved', 1)
            ->selectRaw('company_id, count(id) as total')
            ->groupBy(DB::raw('company_id WITH ROLLUP'));

15th November, 2017

kevbrn started a new conversation UnionAll • 3 weeks ago

I am trying to replicate this query (from SQL Server) in Eloquent.

''' select c.company_name, count(a.id) as 'company_total' from assumptionverifications a left join companies c on a.company_id = c.id where a.approved = 1 group by c.company_name union all select 'all_total' company_id, count(id) from assumptionverifications '''

which works perfectly when directly querying the database.

| company_name | company_total | | ---------------------------- | ------------------- | | Company1 | 37 | | Company2 | 2 | | Company3 | 34 | | Company4 | 41 | | all_total | 159 |

I have tried the following...

''' $avByCompany = AssumptionVerification::with('company') ->where('approved', 1) ->selectRaw('company_id, count(id) as total') ->groupBy('company_id');

    $avTotal = AssumptionVerification::selectRaw("'all_total' company_id, count(id)");

    $results = $avByCompany->unionAll($avTotal);

    return $results;

'''

But I get an error

''' SQLSTATE[22018]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Conversion failed when converting the varchar value 'all_total' to data type int. (SQL: select company_id, count(id) as total from [assumptionverifications] where [approved] = 1 group by [company_id] union all select 'all_total' company_id, count(id) from [assumptionverifications])

'''

Any ideas?

Thanks!

8th November, 2017

kevbrn left a reply on Where To Place Reusable Queries • 1 month ago

Great thank you guys! Ill check out both resources!

kevbrn started a new conversation Where To Place Reusable Queries • 1 month ago

Please excuse the very novice question but if I have a query that I use often but need to pass its results to different views in different parts of my application; I imagine it should be placed in its own class, correct? And if that is the case, where should that class live? A model? A helper? A Service Provider?

Thanks!

5th November, 2017

kevbrn left a reply on Adding A Space.... • 1 month ago

Awesome! Thanks for all your input guys. This community is so helpful!

kevbrn left a reply on Adding A Space.... • 1 month ago

If I do...

  \View::share('sel_userid', User::selectRaw('first_name +' '+ last_name as full_name, id')->where('status', 1)->pluck('full_name', 'id'));

I get ErrorException (E_WARNING) A non-numeric value encountered

This is query is in Providers/AppServiceProvider.php and it populates a form select element.

kevbrn started a new conversation Adding A Space.... • 1 month ago

Anyone know how to go about putting a 'space' between 'first_name' and 'last_name'? If you do, you would be my hero.

 \View::share('sel_userid', User::selectRaw('first_name + last_name as full_name, id')->where('status', 1)->pluck('full_name', 'id'));

Note. I'm using SQL Server 2008 so there is not CONCAT(). Normally I would just do

select first_name +' '+ last_name as full_name from users

But that won't work

Thanks!

2nd November, 2017

kevbrn left a reply on Return Query With Relationship Results To View • 1 month ago

That did it! Oh man, thank you bobbybouwmann! Have been pulling my hair out on this one.

So let me ask; as it will work from both the user and project side, is one more correct than the other?

Also, I had something similar to

    $user = auth()->user(); // Get the current logged in user
    
    $user->load('projects'); // Load the relation of the projects on the user

But PHPstorm is telling me that method 'load' could not be found so I removed it, however it does work when I run it?

Thank you again so very much!

Kevin

kevbrn started a new conversation Return Query Results To View • 1 month ago

Hey all, just getting my hands dirty with laravel and something has me stumped which should seem pretty simple but even after watching 5 Fundamentals, 5.4 From Scratch and Build a Forum with TDD and Laravel I cannot for the life of me pull off the simple task of sending the results of my query to my controller/view.

I have a users, projects and a pivot table, project_user. The table projects contains projects that would have a many-to-many relationship to users and also users have a many-to-many to projects.

In my User model I have...

public function projects()
    {

        return $this->belongsToMany(Project::class)->wherePivot('user_id', 1);

    }
}

// I hard coded the value of user user_id,1 but ultimately this value should be the current logged in user.

In my ProjectsController

public function show(Project $project)
    {
                        
        return view('projects.show', compact('project'));
        
    }

No matter what I do I cannot access the projects() method from the User model. Should I be able to? How do I return the results of my query to the correct controller to pass to my view?

In tinker I get the results that I want, at least it would appear so...

$ php artisan tinker
Psy Shell v0.8.13 (PHP 7.1.9 — cli) by Justin Hilemanan
>>> $user = App\User::find(1);
=> App\User {#778
     id: "1",
     first_name: "Kevin",
     last_name: "XXXX",
     company_name: "XXXX",
     app_role_id: "1",
     project_id: "1",
     discipline_id: "1",
     project_role_id: "1",
     contact_id: "1",
     active_phases: "1",
     status: "1",
     verified: "0",
     email: "XXXX",
     cell_phone: "XXXXX",
     user_profile_pic: "nopic.png",
     created_at: "2017-10-28 16:48:24.000",
     updated_at: "2017-10-28 16:48:24.000",
   }
>>> $user->projects
=> Illuminate\Database\Eloquent\Collection {#774
     all: [
       App\Project {#119
         id: "1",
         ProjectName: "Viper",
         contact_id: "2",
         created_by: "1",
         status: "1",
         created_at: null,
         updated_at: null,
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#777
           user_id: "1",
           project_id: "1",
         },
         contact: App\User {#787
           id: "2",
           first_name: "Robert",
           last_name: "XXXX",
           company_name: "XXXX.",
           app_role_id: "1",
           project_id: "1",
           discipline_id: "1",
           project_role_id: "1",
           contact_id: "1",
           active_phases: "1",
           status: "1",
           verified: "0",
           email: "email address",
           cell_phone: "2223334455",
           user_profile_pic: "nopic.png",
           created_at: "2017-10-30 23:45:42.000",
           updated_at: "2017-10-30 23:45:42.000",
         },
       },
     ],
   }

Appreciate the help!

Thanks, Kevin

Edit Your Profile
Update

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