willvincent

willvincent

Member Since 4 Years Ago

Central Minnesota

Experience Points 325,715
Experience Level 50

0 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 1545
Lessons
Completed
Best Reply Awards 322
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

17 Sep
22 hours ago

willvincent left a reply on Vuex , How Make A Betther Code

I haven't used it, but this looks like it may do everything you need: https://github.com/JiriChara/vuex-crud

willvincent left a reply on How To Customize Working Hours For A Project In Laravel

The easiest option, probably, would be to have a single table with columns for opening/closing times for each of the seven days of the week.

Something like this:

        Schema::create('working_hours', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->time('sunday_open');
            $table->time('sunday_close');
            $table->time('monday_open');
            $table->time('monday_close');
            $table->time('tuesday_open');
            $table->time('tuesday_close');
            $table->time('wednesday_open');
            $table->time('wednesday_close');
            $table->time('thursday_open');
            $table->time('thursday_close');
            $table->time('friday_open');
            $table->time('friday_close');
            $table->time('saturday_open');
            $table->time('saturday_close');
            $table->timestamps();
        });

For your 08:00 - 16:00, just add those as you would expect.. for the other one create two entries, 0:800 - 12:00 and another row with the afternoon times 14:00 - 18:00

That's probably the easiest way to model that data

EDIT: Those of course should all be nullable, :)

willvincent left a reply on What Is The Best Way To Manage An Unregistered Visitor Rating System? Token? IP??

There's not really any perfect solution to this because whatever method you choose will depend on an identifier being unique to an unauthenticated user and remaining so. But you can't necessarily depend on a user's IP address remaining the same, nor that a single IP address is one user or the same user(s) each time it's observed. For example; all users in a large office building may very likely have a single shared public IP address, or mobile phone users IP addresses will routinely get assigned to others on the network, etc.

And as for cookies, nothing is preventing a user from deleting their cookies at any point, or that the user is even allowing cookies.

However -- I would suggest using cookies to prevent duplicate ratings from one user, and just accept that there may be some margin of error if a user clears their cookies/etc. That's more likely to be unique to at least a single device than would an IP address..

Interestingly this was a challenge I was tasked with as a junior developer many years ago, that was a bit more involved than just a rating, instead it was a poll system, so a little more involved but basically just additional choices rather than just a +/- :)

willvincent left a reply on Adding Last_signedin For Users Table

Are you planning to have several more login methods? How soon?

If not, or not soon, worry about things that actually matter and address it when/if it actually becomes an issue. Premature optimization is more often than not unnecessary optimization.

willvincent left a reply on Eloquent Haversine And Ordering By Distance

Try this:

$q->selectRaw('*, (3959 * acos(cos(radians(?))
                     * cos(radians(activity_latitude))
                     * cos(radians(activity_longitude)
                     - radians(?))
                     + sin(radians(?))
                     * sin(radians(activity_latitude)))
               ) AS distance',
               [
                 $geocodedAddress[0],
                 $geocodedAddress[1],
                 $geocodedAddress[0]
               ])->havingRaw("distance < ?", [$radius]);

Probably would actually want that to be users.* or whatever, but I have no context to know what table you're actually querying here :)

willvincent left a reply on Urldecode Route Link In Blade Without Helpers.php

Yea.. not possible, at least not in the address bar of a browser.

See the Wiki page about Internationalized Domain Names:

Although the Domain Name System supports non-ASCII characters, applications such as e-mail and web browsers restrict the characters which can be used as domain names for purposes such as a hostname. Strictly speaking it is the network protocols these applications use that have restrictions on the characters which can be used in domain names, not the applications that have these limitations or the DNS itself. To retain backwards compatibility with the installed base the IETF IDNA Working Group decided that internationalized domain names should be converted to a suitable ASCII-based form that could be handled by web browsers and other user applications. IDNA specifies how this conversion between names written in non-ASCII characters and their ASCII-based representation is performed.

aka "urlencoding"

willvincent left a reply on How To Close All When I Click Someone Open?

Something like this ought to work...

tr.siblings('.shown').removeClass('shown').child.hide()

man, I can't remember the last time I used jquery.. :D

willvincent left a reply on Eloquent Haversine And Ordering By Distance

You've added the haversine formula query within a closure of the whereHas clause. So it's not actually available to the order by. Just guessing since I don't really know what you're working with for a data structure, but try something more like this:

$q = self->whereNull("deleted_at")->where("group_id", 1)
         ->with([
            "data", 
            "businessdata",
            "isopeningtime",
            "contents",
            "contents.translation", 
         ]);

$q->selectRaw('(3959 * acos(cos(radians(?))
                     * cos(radians(activity_latitude))
                     * cos(radians(activity_longitude)
                     - radians(?))
                     + sin(radians(?))
                     * sin(radians(activity_latitude)))
               ) AS distance',
               [
                 $geocodedAddress[0],
                 $geocodedAddress[1],
                 $geocodedAddress[0]
               ])->havingRaw("distance < ?", [$radius]);

$q->whereHas('businessdata')->orderBy('distance', 'desc');
12 Aug
1 month ago

willvincent left a reply on Decimal Lat Lon Vs Geo Spatial Mysql

I'd go a step further and say use postgres with the postgis extension vs mysql. It's far more mature and a ton of development effort each release is focused solely on performance.

10 Aug
1 month ago

willvincent left a reply on Why The Response From The Same Endpoint Is Different

the json() method encodes the data as json, whereas the post() method does not.

See Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:

    /**
     * Visit the given URI with a POST request.
     *
     * @param  string  $uri
     * @param  array  $data
     * @param  array  $headers
     * @return \Illuminate\Foundation\Testing\TestResponse
     */
    public function post($uri, array $data = [], array $headers = [])
    {
        $server = $this->transformHeadersToServerVars($headers);
        return $this->call('POST', $uri, $data, [], [], $server);
    }
    /**
     * Call the given URI with a JSON request.
     *
     * @param  string  $method
     * @param  string  $uri
     * @param  array  $data
     * @param  array  $headers
     * @return \Illuminate\Foundation\Testing\TestResponse
     */
    public function json($method, $uri, array $data = [], array $headers = [])
    {
        $files = $this->extractFilesFromDataArray($data);
        $content = json_encode($data);
        $headers = array_merge([
            'CONTENT_LENGTH' => mb_strlen($content, '8bit'),
            'CONTENT_TYPE' => 'application/json',
            'Accept' => 'application/json',
        ], $headers);
        return $this->call(
            $method, $uri, [], [], $files, $this->transformHeadersToServerVars($headers), $content
        );
    }

Good rule of thumb, when in doubt, look at the underlying methods you're calling to see what they do. :)

06 Aug
1 month ago

willvincent left a reply on How To Remove Data Where The Child Table That Has Less Than 1 Value In Laravel 4

I see.. so always show the parent(s), only include children matching the desired criteria.

Parent::with('Child', function($query) {
  $query->whereRaw('column1 - column2 > ?', [0])
})

That'll include children matching the criteria on the parent, and show every parent.

If instead you just want to show parents that have one or more child matching the criteria change that with back to your original whereHas

That should be what you're after

willvincent left a reply on Form Dosen't Submit All Data

Moment can parse any date string, so long as you provide it the appropriate format as the second param ..

So for end:Fri Aug 16 2019 00:00:00 GMT+0000 (Greenwich Mean Time)

So long as they're always UTC, this would work to parse: moment(str.replace('end:', ''), 'ddd MMM D YYYY HH:mm:ss ZZ')

If you need to parse the timezone too you'll probably need the moment tz addon too but, that's the basic gist, you provide the string to parse, and the string defining the format

willvincent left a reply on Get A Data From The Sql Using Laravel

We can not change all the things because it is already live so we have to handle this way only.

That's not necessarily true. It would probably be easier to migrate the existing data to a more usable format than conform your logic to badly designed data.

04 Aug
1 month ago

willvincent left a reply on Pass Multiple Values To The Same Function Within A Controller

if it is possible

Sure.. but just because you can doesn't mean you should

willvincent left a reply on How To Remove Data Where The Child Table That Has Less Than 1 Value In Laravel 4

I think I understand. So you want to find and delete from the DB where the total of column1 - column2 is less than 1...

Or put another way;

Given a Parent record has a Child record

When the total of children.column1 - children.column2 is less than 1

Remove the Parent AND Child ?

I assume this would be run via some sort of recurring schedule then probably.. but that's a separate issue, lets worry about the query itself. If you have the foreign key configured, and have children set to cascade delete when parent is deleted that simplifies things considerably.. so I'll assume you do.

I think this would achieve this:

Parent::whereHas('Child', function($query) {
  $query->where('status', 2)->whereRaw('column1 - column2', '<', 1)
})->delete();

Obviously test that before running in production since it's destructive :)

If you don't have the foreign key with cascading deletion setup, you'd want to instead directly query the children, gather the parent_ids from the matching results, and then delete the matching records, and separately do like a Parent::destroy($array_of_parent_ids)

willvincent left a reply on How To Get Random Question But Non Repeatable

Well first off, you're not running a single query anyway since you're eager loading answers, so no need to worry about that. That out of the way, invert the logic, and fetch the answered question ids first, then use for a where not in clause..

Something like this:

$asked_ids = Result::where('user_id', Auth::user()->id)
                      ->pluck('question_id');

$question = Question::with('answers')
                      ->whereNotIn('id', $asked_ids)
                      ->inRandomOrder()
                      ->first();

Can't remember if you need to tack a ->toArray() on that first query or not before using it in a where[not]In clause.

But... that should grab you the first random question not yet asked to the authenticated user

willvincent left a reply on Adding Multiple Notification Channels To The User Model.

Have been away from laravel for a few years, and don't have first-hand experience with notification channels... seems like a misconfiguration somewhere though as the docs pretty clearly indicate that you return an array of channels..

Probably a missing something somewhere that properly ushers things into the appropriate notification channel by defined type.

Probably relevant:

To route Slack notifications to the proper location, define a routeNotificationForSlack method on your notifiable entity.

https://laravel.com/docs/5.8/notifications#routing-slack-notifications

willvincent left a reply on Custom Query To Eloquent

Sometimes it really is easier to roll with a raw query.

Not everything needs to be run through eloquent ;)

willvincent left a reply on Form Dosen't Submit All Data

Ok, in that case, you probably need to specify the date format for moment to parse:

methods: {
  axios.post('/api/booking/create', { 

    // ignoring other parts for convenience

    days: this.numberOfDays,

  });
},

computed: {
  numberOfDays: function () {
    return Math.abs(
      moment(this.selectedValue.start, 'MM/DD/YYYY').diff(
        moment(this.selectedValue.end, 'MM/DD/YYYY'), 'days')
      )
    );
  }
}

But... it is working elsewhere? thats... weird.

Are you certain the issue is on the vue side? Assuming it's able to properly parse dates from this.selectedValue that logic should always yield a value between 0 and whatever the upper limit of range you allow to be selected is.

Could be passing a 0 and the server side code is seeing that as falsey maybe?

willvincent left a reply on Vue Router Component Needs Reloading In Order To Function Properly

Instead of pushing the path, have you tried router.go(-1) to actually go back in the navigation history to the previous page?

There's not really much to go on here, your images look to be a styling issue, something preventing styles applying properly the second time, but if you're saying things aren't functioning properly either, there's something more going on.

Sounds like probably a state and/or lifecycle issue

willvincent left a reply on Are You Also New? Is Your .env Showing?

Yeah.. /public should always be the docroot for a laravel project such that anything outside of it is not accessible unless a laravel route serves it up.. Who taught you this terrible other way? That sort of bad advice really ought to warrant naming and shaming.

shame

willvincent left a reply on Form Dosen't Submit All Data

Do you need it to be a computed property? Are you using that computed value elsewhere, and if so is it working?

It's entirely possible and likely that moment is failing to parse the dates since you're not providing the format as you are when defining dropOffDate and pickUpDate in your post body.

also this is entirely the wrong place to define a variable... ;)

methods: {
        const val = this.numberOfDays;

If you don't need the computed prop elsewhere, why not just compute it directly when prepping the axios post body? Then, since presumably dropOffDate and pickUpDate are working you could instead do somethign like this...

// get rid of the computed prop altogether...

// method becomes:

methods: {
        createBooking() {

            const dropOffDate = moment(this.selectedValue.start, "MM/DD/YYYY");
            const pickUpDate = moment(this.selectedValue.end, "MM/DD/YYYY");

            axios.post('/api/booking/create', { 
                carNumber: this.booking.carNumber,
                carSize: this.booking.carSize,
                carType: this.booking.carType,
                carSubtype: this.booking.carSubtype,
                carColor: this.booking.carColor,
                name: this.booking.name,
                socialId: this.booking.socialId,
                email: this.booking.email,
                phone: this.booking.phone,

                dropOffDate,


                dropOffTime: this.booking.dropOffTime,


                pickUpDate,


                pickUpTime: this.booking.pickUpTime,
                flightNumber: this.booking.flightNumber,


                dates: Math.abs(dropOffDate.diff(pickUpDate, 'days')),


                priceForDays: this.priceForDays,
                totalPrice: this.price,
                finalPrice: 100
            })
            .catch(error => {
                error.response.data;
            })
            .then(function (response) {})
        }
    },

I added extra spacing so my changes stick out. If you have a variable of the name already, you can just reference that without having to assign it's value, thus the dropOffDate, and pickUpDate, in the post body now, since they're defined earlier, and then also used to set your dates value.

Assuming your date logic was sound in the first place, this should work

willvincent left a reply on Change Column Names For The Auth

Even if you don't want a secure site, there's a good chance your users do.. so yeah, please don't use md5 :)

willvincent left a reply on Form Dosen't Submit All Data

Your computed property is manipulating scope variables, that's not good. Instead maybe try:

computed: {
  numberOfDays: function () {
    return Math.abs(
      moment(this.selectedValue.start).diff(
        moment(this.selectedValue.end), 'days')
      )
    );
  }
}

If you really feel it's necessary to break those out into variables, keep 'em local to the computed method instead of manipulating this.start and this.end from within the computed method.

Computed methods, generally, aren't meant to do any setting .. when that is needed (and it doesn't appear to be here) there is a different syntax available to define setter and getter on a computed prop.

willvincent left a reply on Adding Multiple Notification Channels To The User Model.

Your via() method would simply have to return an array of all the relevant channels configured for the user being notified, for any given notification event... no?

03 Aug
1 month ago

willvincent left a reply on How To Duplicate Laravel Collection

What if the query is very long (3 lines) and I try to avoid code duplication

Might make sense to abstract a query scope... Or simplify it some, seems maybe overcomplicated if you're having to write a lengthy query to determine latest and oldest of a collection, that really ought to be based on a single field value, no?

willvincent left a reply on How To Create A New Record If Not Exist Or Update If It Exists

firstOrCreate() would be appropriate in this case.

$credit = Credit::firstOrCreate(['user_id' => Auth::user()->id]);
$credit->increment('amount', 600);
$credit->refresh();

Perhaps you need to rtfm, joyner. ;)

31 Dec
1 year ago

willvincent left a reply on Hints For First Time Users Plugin?

I don't have anything to share. all the requisite info should be right there in Steps 1-5 on the linked page.

03 Oct
1 year ago

willvincent left a reply on Understanding About Helper.

I would like to know if this breaking the flow of MVC pattern? Because we are running DB queries directly from helper method used in view file.

Yes, of course that breaks the MVC pattern. That's entirely the wrong way to do it.

11 May
2 years ago

willvincent left a reply on JSON File As A Data Source

I dunno about doing it with eloquent, but you can pretty easily build a fake rest server around a json file with the json server nodejs package.

23 Apr
2 years ago

willvincent left a reply on Make Php Artisan Serve Multi Threaded

[2017-04-23 09:35:20] production.ERROR: RuntimeException: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths. in C:\wamp64\www\GoAP\vendor\laravel\framework\src\Illuminate\Encryption\Encrypter.php:43

You need to ensure you have the mcrypt extension installed and enabled. Check your wamp php config.

22 Apr
2 years ago

willvincent left a reply on L5 - Best Way To Get User Timezone

https://momentjs.com/timezone/

moment.tz.guess() will attempt to get the timezone name from the client browser.

The most foolproof method is to have the user manually set their own timezone.

EDIT: Damn, old thread. @kjdion84 Why are you reviving all these old threads?

21 Apr
2 years ago

willvincent left a reply on Laravel IDE

There are already many IDE's that work great with PHP. I switch between sublime and phpstorm, and occasionally VSCode (though usually only for javascript or C# in it). There's not only no need for yet another IDE, but you'd be hard pressed to find a better IDE for php development than phpstorm.

willvincent left a reply on Learning JavaScript

The ES2015 (aka es6) series would definitely not be a waste of time.

20 Apr
2 years ago

willvincent left a reply on How To Refactor Laravel PHP Code In Sublime ?

I've never used it, but there is a refactor php package for sublime.

https://packagecontrol.io/packages/PhpSimpleRefactor

willvincent left a reply on Is It Possible To Connect Two Database Table Rows?

@jlrdw but the OP isn't doing any sort of backups, this is simply about a different type of user.

There's literally no reason for anything more complex here than either a boolean column on the table indicating the user is an admin, or a user role system. No need for a separate table nor a second model pointing at the same table.

Good time to employ the KISS principle. ;)

willvincent left a reply on Laravel IDE

artisan can already do some code generation, any more than what it does is pretty unnecessary and if you find more to be necessary for you, that's what snippets and live templates are for.

phpStorm is a great IDE for any php application, laravel or otherwise, a laravel specific IDE (which it seems is what you're asking for) is unnecessary and never need be developed.

willvincent left a reply on Is It Possible To Connect Two Database Table Rows?

You can, sure.. that too seems somewhat unnecessary though ;)

willvincent left a reply on Syntax Error, Unexpected '<' In View

Exactly, don't put a full block of PHP into your template, that's very bad practice.

That said, the specific problem(s) causing the error are the markup within your opening and closing php tags. That syntax is just entirely flawed.

willvincent left a reply on Query And Comparing 2 Tables

Get list of product ids purchased by the specific user, then use those as part of a whereNotIn clause.

For example:

$purchased_ids = Purchase::where('user_id', 12)->pluck('product_id')->all();

$unpurchased = Product::whereNotIn('id', $purchased_ids)->get();

You could also accomplish it with a join, but the performance improvement would most likely be negligible in this case.

willvincent left a reply on Is It Possible To Connect Two Database Table Rows?

Seems like it's probably unnecessary to have separate tables for these since they're pretty much just a different type of user, that could be handled with roles or even a simple boolean flag indicating that a user is an admin.

But, if you're determined to use two tables, and the ID in the admin table needs to match that of the id within the user table, why not just make the admin's ID an unsigned, non-nullable integer (not auto-incrementing) and manually set it to the same as the user ID when doing your inserts and updates?

willvincent left a reply on Search Not Work In Laravel 5.4

Either you didn't read the rest of my comment, or you must not really want help... "Doesn't work" isn't really useful. It tells us absolutely nothing about the real problem.

willvincent left a reply on Send SMS Notification

First check if the one you want to use already has a channel provider: http://laravel-notification-channels.com/

If you can't find it, write your own custom provider

willvincent left a reply on Clicking On The Server Link Does Not Work

That part of the output from that command doesn't appear as a link for me. Where are you seeing it at a link? Or are you just assuming that it should be a link?

willvincent left a reply on Search Not Work In Laravel 5.4

You've provided a lot of code which is nice, but you're not really being clear about the issue.. just saying "It doesn't work" isn't really very descriptive. How does it not work? What is happening that shouldn't be, or what is not happening that should be. Any error messages?

If that javascript is the entire JS, your issue is probably that you're not waiting for the dom to be ready before attempting to bind autocomplete to your search element. Simply wrapping a document ready function around your JS might be all that's necessary.. without more information though that's a total stab in the dark.

(function ($) {
  $(document).ready(function() {
    $('#searchname').autocomplete({
      source : '/autocomplete', // <-- this should be sufficient
      minlength: 1,
      autoFocus: true,
      select: function(e,ui){
        //$('#id').val(ui.item.id);
        //$('#name').val(ui.item.value);
      }
    });
  });
})(jQuery)

The first & last lines aren't necessarily required, but it's a good convention to use and works even if jquery isn't bound to the dollar sign variable name for one of several reasons that can be the case.

willvincent left a reply on Deployed Changes Aren't Showing On Site

To be clear you want opcache enabled.. your performance would very noticeably suffer without it.

But since you are running nginx, restarting that process won't make a difference, you need to restart your php-fpm process. Unlike is often the case with apache, php does not get built as a module for the webserver directly, but runs as it's own separate process.

willvincent left a reply on Deployed Changes Aren't Showing On Site

You've probably got php opcode caching or something along those lines enabled on the server. So while you don't need to reboot the server you would probably need to restart the webserver and/or php processes.

willvincent left a reply on Sending Email After Specific Date

Are you working in a windows environment? It doesn't have cron.

19 Apr
2 years ago

willvincent left a reply on Sending Email After Specific Date

@sandstorm as @jekinney suggested, yes I think that makes the most sense in your case given the length of the delay you're looking for before taking action.