wilk_randall

Full-stack Developer at Invizon

Experience

74,010

58 Best Reply Awards

  • Member Since 11 Months Ago
  • 352 Lessons Completed
  • 0 Favorites

17th June, 2018

wilk_randall left a reply on How To Replace A Dot With A Comma For A Number In Vue.js? • 2 days ago

You could also do it with a filter like this:

<p>{{ quantity | formatQuantity }}</p>
new Vue({
    el: '#app',

    data: {
        quantity: 0.25,
    },

    filters: {
        // you can call this whatever you want to
        formatQuantity (value) {
            return value.replace('.', ',');
        }
    }
});

13th June, 2018

wilk_randall left a reply on Tabs In Laravel • 6 days ago

@LorienDarenya - If you don't want to use Bootstrap, I suggest looking at this: https://jqueryui.com/tabs/

wilk_randall left a reply on Values Or Names With Dash Or Hyphen • 6 days ago

Try getting it like this instead: $domainname = $request->get('domain-name');

12th June, 2018

wilk_randall left a reply on How To Send Email When Subscription Ends? • 1 week ago

If you have some kind of expiration date on the table, you could run a scheduled command every day to email the users of the expired ones.

https://laravel.com/docs/5.6/scheduling

9th June, 2018

wilk_randall left a reply on How To Give Variables To The Master Layout • 1 week ago

I think the best option is to use a ViewComposer.

https://laravel.com/docs/5.6/views#view-composers

wilk_randall left a reply on Traits In Laravel • 1 week ago

Traits do become part of the object when they are used in a class. It's helpful that the documentation lists them because each of these traits has additional methods and properties that are available to the class. Without listing them, you wouldn't know about these methods and properties.

wilk_randall left a reply on Get PHP Class Namespace From String • 1 week ago

@Cronix - I don't think it's going to work (unless I'm doing it wrong). If I do it on a plain string I get a ReflectionException because the class doesn't exist.

Perhaps I should have specified my use case before. My use case is I'm generating a class with an artisan command, and I need to get the namespace part of the class to append to the default namespace. For example, one type of class I'm generating is a repository, which I have the directory set to Repositories.

Here is an example of the command usage: php artisan make:repository Backend/ProductRepository

I need to be able to extract the Backend part of the string so my generated namespace will get set to Repositories\Backend in the stub file. Since the class doesn't exist, reflection isn't working for me, but a slight modification of the selected answer's code above does.

8th June, 2018

wilk_randall left a reply on Get PHP Class Namespace From String • 1 week ago

@Cronix - Would this work for any string or does the class need to exist in the application?

wilk_randall left a reply on Which Directories / Files Can I Remove Safely From The Laravel Package? • 1 week ago

"Do you realize how much easier updating would be with composer."

One day i will try it, when i have the time.

It probably takes you longer to do all of this than it would to just use composer to manage your dependencies.

wilk_randall left a reply on Get PHP Class Namespace From String • 1 week ago

@casnv18 - Thanks for the reply. I kind of figured that would be the case unfortunately and you've confirmed that for me.

7th June, 2018

wilk_randall started a new conversation Get PHP Class Namespace From String • 1 week ago

I'm not sure if I'm looking in the wrong places or what, but all I can find are ways to get the class name from a string using something like class_basename(). This is the opposite of what I want; I'm looking to get the namespace from it instead.

For example, if I had the string App\Http\Controllers\Controller, I want to get the App\Http\Controllers part from the string. Of course I could explode on the \ character and just remove the last element from the array, but I am hoping to find something with similar functionality to class_basename but for the namespace instead.

6th June, 2018

wilk_randall left a reply on Json Being Displayed Instead On Vue Component When Browser's Back <- Button Is Clicked • 1 week ago

@nigelhv - You need to do it in a separate route and controller function.

5th June, 2018

wilk_randall left a reply on How Can I Compare Two Array Of Objects A Give The Difference • 2 weeks ago

@Melodia - I think a whereNotIn query would work.

// query based off your code above
$subjects = Subject::where('course_id', $course)->whereNotIn('id', $student_id->subjects()->pluck('id'))->get();

wilk_randall left a reply on How Can I Compare Two Array Of Objects A Give The Difference • 2 weeks ago

Why wouldn't you just query for the subjects that a user is not registered at in the first place? It makes no sense to do what you're doing.

21st May, 2018

wilk_randall left a reply on How I Convert Data Like This? • 4 weeks ago

If you have the permissions stored as a column on a model, you could automatically have it casted as an array or object like this:

protected $casts = [
    'permissions' => 'object'
];

If you don't want to cast, or if it's not stored on a model, what @Cronix said works perfectly well too.

20th May, 2018

wilk_randall left a reply on Question • 4 weeks ago

There is currently no functionality to do this. It's better to mark an answer as the best reply and keep your original question so that others who have the same question can get help from it as well.

16th May, 2018

wilk_randall left a reply on Can't Use Sessions In Laravel Controller • 1 month ago

In WordPress "functions.php" i use that code, zero problems:

Of course you're not going to have problems; WordPress is mostly procedural. Are you unwilling to adapt to newer programming practices or something? OOP makes for much easier to maintain code, as well as reusable code.

wilk_randall left a reply on Can't Use Sessions In Laravel Controller • 1 month ago

I don't think you even understand much about object oriented concepts... I have never needed to use the global keyword inside of a class and I have definitely never put code like you are outside of the class when it could be used in a class method instead. You seem to be stuck in a procedural mindset. Perhaps you should watch one of these video series to catch up...

https://laracasts.com/series/object-oriented-bootcamp-in-php

https://laracasts.com/series/laravel-from-scratch-2017

14th May, 2018

wilk_randall left a reply on Laravel Mix And React Js • 1 month ago

@alexluk - Try something like this instead:

export default class Example extends Component {
    constructor(props) {
        super(props);
        this.state = { storeurl: false };
    }
}

Also, for future reference, you should start a new thread for your questions, especially since what you have isn't really related to this. All you have is a syntax error, which is also clearly stated in the error.

11th May, 2018

wilk_randall left a reply on FormData Becomes An Object Instead Of Array? • 1 month ago

Try this instead:

this.form.locations.forEach((location, i) => form.append(`locations[${i}]`, location));

wilk_randall left a reply on FormData Becomes An Object Instead Of Array? • 1 month ago

You need to iterate over the locations and add each one to the FormData.

10th May, 2018

wilk_randall left a reply on Modifying Data In Methods Doesn't Seem To Work • 1 month ago

I think it might have something to do with the fact that your toggle click event is on the entire div, so it's going to happen every time you click any where in the div, including your buttons. I think the most simple solution would to do something like this for the buttons:

<button @click.prevent.stop="handleSave">Save</button>
<button @click.prevent.stop="handleCancel">X</button>

wilk_randall left a reply on Best Practices - Observers And Providers • 1 month ago

Typically I like to create an observer class for each model I need to observe, and then register the observer directly on the model, so there is no need for a provider to register them.

To register the observer on the model, do something like this:

class YourModel extends Model
{
    protected static function boot()
    {
        parent::boot();
        static::observe(YourModelObserver::class);
    }
}

9th May, 2018

wilk_randall left a reply on Vue JS And Ajax Request. • 1 month ago

Yes, use xhr.

7th May, 2018

wilk_randall left a reply on Add Id From V-for To Dom Elements • 1 month ago

@nanadjei2 I'm aware that's not the problem. As far as I'm aware, v-for only takes 2 parameters, that's why I changed that. Also, my bad for not looking closer at your url in the form, as I figured the rest of the code could have stayed the same. You need to change to action to something like this:

<form :action=`${baseUrl}/${user.id}` method="POST">

wilk_randall left a reply on Add Id From V-for To Dom Elements • 1 month ago

Try this instead:

<tr v-for="(user, index) in users">
    <td>@{{ index + 1 }}</td>
    ....

wilk_randall left a reply on How To Fetch Latest 4 Posts And In Next Request Get Next 4 Requests • 1 month ago

You need to include the page number with the request, otherwise it's going to show the first page.

4th May, 2018

wilk_randall left a reply on Trouble With Vuex && Computed • 1 month ago

It looks like you don't have user defined in your computed, and you're also referencing it wrong in your mounted function. Try this instead:

computed: {
    user () {
        return this.$store.state.user;
    }
},

mounted () {
    if (this.user) {
        console.log('do something');
    }
}

3rd May, 2018

wilk_randall left a reply on Upload Video With Big Size • 1 month ago

Tbh it's usually better to host videos on something like Youtube or Vimeo as videos can use up a lot of bandwidth. I would only worry about uploading videos if the project is on a server that can handle the loads.

wilk_randall left a reply on Sass • 1 month ago

Do you have source maps enabled?

wilk_randall left a reply on Generating A Unique Token • 1 month ago

I have a helper function I use to do something like this:

function generateToken()
{
    return md5(rand(1, 10) . microtime());
}

2nd May, 2018

wilk_randall left a reply on Single File Vue.js Filters • 1 month ago

I suggest you check this package out: https://github.com/jofftiquez/vue-morphling

I would either use the package, or emulate how they do things.

1st May, 2018

wilk_randall started a new conversation Vue Render Element Function • 1 month ago

I'm rendering a component via the render function, which is working fine, but there is something I want to change about it, but not sure if it's possible or how to do it. Currently, my component can accept an icon prop, and if set, will prepend an icon to the content. In order to render both the icon and the the name passed in, I'm rendering the name in a span in order to be able to show them both. Is it possible to render both the icon and the name without me having to put the name in a span?

My component code below:

import { mergeData } from 'vue-functional-data-merge';

export default {
    functional: true,
    
    props: {
        icon: {
            type: String,
            default: ''
        },
        name: {
            type: String,
            required: true
        },
        url: {
            type: String,
            default: '#'
        }
    },

    render (h, { props, data }) {
        let children = [];

        if (props.icon && props.icon.length) {
            children.push(h(
                'i',
                { staticClass: props.icon }
            ));
        }

        children.push(h(
            'span',
            {
                domProps: { innerText: props.name }
            }
        ));

        return h(
            'a',
            mergeData(data, {
                attrs: {
                    href: props.url
                }
                // ideally name would be inserted here instead of with children
                // but if I do that, the icon never gets inserted.
            }),
            children
        );
    } 
}

wilk_randall left a reply on Showing Different Activity On Timestamps • 1 month ago

IMO that's not a good way to keep track of activity. It's just not maintainable, especially if you need to add more models in to the mix. You're better off using some kind of activity tracking table like this: https://github.com/spatie/laravel-activitylog

28th April, 2018

wilk_randall left a reply on Clicking Back Displays JSON Response • 1 month ago

@biishmar - Why would you use validation in the controller method when Request class being used handles that itself??

wilk_randall left a reply on After Encrypt An Id, Can't Go To The Function In Controller To Decrypt It. • 1 month ago

bcrypt will never give you the same result twice. Encrypting the id like you are is fine, but you won't be able to bind the model to the route like you are. You will first need to use the decrypt function on the id, and then find the group.

Personally, I wouldn't do it that way, I'd actually use something like this package to generate a uuid for your models that you can use: https://github.com/webpatser/laravel-uuid

26th April, 2018

wilk_randall left a reply on Creating Non Reactive Copies Of Vue Data • 1 month ago

I like to use Object.assign() as mentioned above, or if you use a library such as lodash, you can use _.clone(obj) or _.cloneDeep(obj).

25th April, 2018

wilk_randall left a reply on How Do I Get Data Returned From A Method In The Model Into Vue? • 1 month ago

Couldn't Transaction be a relationship to your model? Then you could just include that in a with in the query and then calculate the total in the vue component.

20th April, 2018

wilk_randall left a reply on Vue Watch Doesnt Get Triggered When Using Axios • 1 month ago

Try this:

Vue.set(this, 'autocompleteOn', true);

17th April, 2018

wilk_randall left a reply on Twitter Dms With Laravel?? • 2 months ago

Refer to their API documentation: https://developer.twitter.com/en/docs

16th April, 2018

wilk_randall left a reply on How To Load Javascript ES6 Class In View? • 2 months ago

you have to use import. Also, I'm not sure if you can import in a blade as I've never tried it; I always am using external scripts for everything, that way everything can be in laravel mix.

import Person from './path/to/person.js;

14th April, 2018

wilk_randall left a reply on Send Checkbox Value To Controller Using Laravel Blade And Javascript • 2 months ago

You are lacking knowledge of some basic programming concepts. You really should learn the basics of PHP and JavaScript first.

wilk_randall left a reply on Route Validation • 2 months ago

Personally I think it's better to not use a global approach like you are wanting because you have more control over authorization for each model when you have policies for each of them. Sure you could abstract some common logic into a base class or trait, but it's not really a big deal to have a policy for each model.

13th April, 2018

wilk_randall left a reply on Laravel To VueJs Limit Characters To Show • 2 months ago

Like @spekkionu had said, you can't run PHP code with JavaScript. With Vue, you could make a method to get the post body, or if each post is in their own component, you could do it as a computed value.

<template>
    <div>
        <div v-for="post in posts">
            {{ getPostBody(post) }}
        </div>
    </div>
</template>

<script>
export default {
    methods: {
        getPostBody (post) {
            let body = this.stripTags(post.body);

            return body.length > 300 ? body.substring(0, 300) + '...' : body;           
        },

        stripTags (text) {
            return text.replace(/(<([^>]+)>)/ig, '');
        }
    }
}
</script>

wilk_randall left a reply on Eloquent Multiple Relationship With Condition • 2 months ago

@sane79 - It isn't actually a relation, it's an accessor, so you should have access to the model's data. Can you show your code of how you did it?

12th April, 2018

wilk_randall left a reply on Eloquent Multiple Relationship With Condition • 2 months ago

I had a notification model that could apply to three different models: Property, Rental, or Service.

public function getItemAttribute()
{
    switch ($this->type) {
        case 'property':
            return Property::where('id', $this->item_id)->firstOrNew([], ['title' => 'Property']);
        // Same thing for other two
    }
}

// to use it
$notification->item->title;

Looking back at it, I probably could of done it with a Polymorphic relationship, but I didn't think of it at the time.

wilk_randall left a reply on Eloquent Multiple Relationship With Condition • 2 months ago

I've tried this before but had the same problem you were having, so instead (although not the most desirable solution) I made it into an accessor on the model.

11th April, 2018

wilk_randall left a reply on Apply Sql Case On Select All In Laravel • 2 months ago

@baloch - You could also make a custom accessor that you only need to reference where you need it.

public function getPick8BooleanAttribute($value)
{
    return (int) $value === 1;
}

// usuage
$product->pick_8_boolean;
Edit Your Profile
Update

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