Jaytee

Software Developer at N/A

Member Since 4 Years Ago

Christchurch, New Zealand

Experience Points
184,345
Total
Experience

655 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
873
Lessons
Completed
Best Reply Awards
150
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.

Level 37
184,345 XP
Nov
18
1 day ago
Activity icon

Awarded Best Reply on File Not Deleted After Beginning Send Response And Break The Connect

Of course it wouldn't. If the user closes the browser before the download has finished, the download will be cancelled, thus it won't be deleted.

You could check if a current ZIP exists, if it does, allow the user to download that zip, without generating another one, and then delete it.

If it doesn't exist, create it, and then allow them to download it. Then delete it.

Could also run a Job which deletes ZIPs after a certain amount of time.

Nov
15
4 days ago
Activity icon

Replied to Mix Cannot Find Dependencies For App.js And App.scss

@smitpatelx This entire thread is not relevant anymore. Those values will work for Laravel 5.8/6 apps, but not for the versions that were released 2 years ago.

Consider thinking about this before posting. Versioning changes fast, and plays a factor in whether an app works or not.

Activity icon

Replied to Laravel Collective - Different Label Name And Input Name

Don't use Collective, it's no longer relevant or advantageous in Laravel.

Define your forms explicitly using HTML.

Nov
14
5 days ago
Activity icon

Awarded Best Reply on Sendgrid Emails Are Not Delivering Sometimes

Mailables should ideally be pushed to a queue (changing ->send() to ->queue(), will work, but you'll also need to setup queues so consult the docs) will certainly help.

It could be that it's actually timing out. Jobs that fail (e.g: mail that fails to send) will stay in a failed_jobs table in your database, to which you can use as an indication.

If the job has run successfully, but the user still doesn't receive it, i'd be looking at SendGrid or a different service.

Usually in this case tho, it's because of one or multiple reasons:

  1. Not using queues, therefore the user has to wait for the mail to be sent. Could be a timeout issue, or a connection loss etc

  2. Job failing. Usually jobs will fail if there's an error in the code. You can set the amount of times it will try to run the job and the timeout etc.

  3. The service sending the mail.

  4. User has entered incorrect information like an email address etc.

Activity icon

Awarded Best Reply on Create Default Data When New Users Are Created

You can do it at the database level by chaining on ->default('value here') to the table definitions in your code above.

You'll still need to create the record when a user is created. To do this, you can either listen for the Login event, or look into the trait that is used on the registration controller, which provides a method that is called after a user is created. If you take the latter approach, you'll need to copy that method into the controller, not modify the trait.

Note that you're working with dates, and more specifically times, so you'll need to the appropriate time and format like: 00:00.

An alternative would be to use ->decimal() instead, to which you store it in hours, e.g: 8.5 = 8 and a half hours, but your calculations for determining the correct rates would need to be precise, as we only have 60minutes in an hour (which you think as being able to divide by 6), but an integer can be divided by 10, if you understand what I mean.

For time: once it hits 23:59 it'll reset back to 00:00 when using libraries like carbon for calculations.

With decimals, it's more accurate and common to what we would see in an HR database these days, but you'll need to actually calculate the exact overtime.

For an easier approach, store it in minutes (a bigInteger would suffice). No calculations would be required, and it'd be easy to convert into hours.

Nov
13
6 days ago
Activity icon

Replied to Flip() Collection Between Model And Relations?

Much better. I'll be back on my PC soon, then I can help. It's not complicated now that we're aware of the details.

Activity icon

Awarded Best Reply on Laravel Vue Component Method Not Firing

I've created an app and created the tabs component as per the laracasts episode. I'm using the latest versions of Vue and Laravel etc.

I didn't receive any errors, and all worked fine for me.

I've created a repository, clone it and run it and see if it still fails for you. It shouldn't:

https://github.com/JayteeOCE/vue-tabs-laracasts

One thing that I did do, which may be the cause, is to quadruple-check that you're using the correct component files. I had <tabs> and <tab> at first, but <tab> was returning the <tabs> component instead due to a spelling error. I can see your post above shows that you've correctly defined your components, but just double check.

Activity icon

Replied to Laravel RESTful API With X-API-KEY Header

Don't bump a 4 year old thread.

Activity icon

Replied to Event.$on('somethingHappened'. () => This.doStuff()); <- Where To Put This ?

Usually in one of the lifecycle hooks, like mounted()

Activity icon

Replied to Searching Products Slow - Cache Image?

Depends how you're searching. Do you mean you're search a product through an input/search bar which hits the database, or at the database level, with a query?

Activity icon

Replied to Unable To Get Google Adwords Campaign Data

You sure you don't need to assign the results back to a variable?

Looks like that's the default class structure with the default fields.

$ads = $ads->service(CampaignService::class)
            ->select(['Id', 'Name', 'Status', 'ServingStatus', 'StartDate', 'EndDate'])
            ->get()

Might aswell just remove the select statement too, looks like they're the only properties it has.

$ads->service(CampaignService::class)->get()

Activity icon

Replied to Storage::allFiles('directory'); Giving Wrong Return?

Yep, you could just use a loop and in_array() on the files, to filter out the dots into a new array.

Best not to just chop off the first two indexes incase they change order

(Sorry, on phone)

Activity icon

Awarded Best Reply on Storage::allFiles('directory'); Giving Wrong Return?

Try using Storage::files() instead. allFiles() also returns subdirectories, so it's probably counting the main directory too.

To be honest tho, probably not worth using the Filesystem in Laravel if all you're doing is getting the list of files, would be more efficient to use a SPL function like: https://www.php.net/manual/en/function.scandir.php

Activity icon

Replied to Can't Install Dependencies Globally

Global files generally require sudo since you're modifying the actual server directory, rather than the local project directory.

Activity icon

Awarded Best Reply on Can't Install Dependencies Globally

Try with sudo

Nov
12
1 week ago
Activity icon

Replied to GroupBy Specific Key And Return The Collection

Yeah, if you're handling data from the DB, use what @jlrdw said.

If dealing with static data, here's another way. It should, in theory work:

$collection = collect([
    'catalogue1' => [
        'Alex',
        'John'
    ],
    'catalogue2' => collect([
        ['account_id' => 'account-x10', 'product' => 'Chair'],
        ['account_id' => 'account-x10', 'product' => 'Bookcase'],
        ['account_id' => 'account-x11', 'product' => 'Desk'],
    ])->groupBy('account_id')
]);
Activity icon

Replied to Can't Install Dependencies Globally

Try with sudo

Activity icon

Replied to Storage::allFiles('directory'); Giving Wrong Return?

Try using Storage::files() instead. allFiles() also returns subdirectories, so it's probably counting the main directory too.

To be honest tho, probably not worth using the Filesystem in Laravel if all you're doing is getting the list of files, would be more efficient to use a SPL function like: https://www.php.net/manual/en/function.scandir.php

Activity icon

Replied to Flip() Collection Between Model And Relations?

Your first post was not clear enough. It's only clear enough for you, because you know what you're trying to achieve, but we don't. The keywords you mentioned are: flip, and relations and you want a collection of user models, where each model has a comment relation.

Your image, points to Comment and user and you say you want to flip that, again, no mention of wanting a count.

No where in that paragraph, does it state you want the count of users for a post, until your second reply.

Rephrase your question next time, and make it relevant. If you want the count of users for a post, say that.

And then once again, it's not just a simple solution to provide, because up until you posting that second thread, I didn't know you were using polymorphic relations.

Be clear on stuff. You want a count, we need to know the relations you have, what you need etc.

So what is it that you want? You have a collection of comments, and they all have a user relation, yep?

Good, now carry on.

?flip?, What do you mean by this? When we say this, we usually mean reversing the key and value.

You want to "flip" the collection so that you have a collection of User models which have their relation with a comment.

So do you actually want a collection of users with comments, or do you want a collection of users for a particular comment, which also has all of their comments, in which case, irrelevant.

Or do you want a collection of users for a particular comment, but a distinct list?

In reality, getting the count for a post should be dead fucking simple, but the way that you're putting (based on your three threads regarding this) is making it so complicated.

map the data out that you have currently (in an array format) and then also map out an array format (for the data you want), show us both of those, and then people can help you.

Activity icon

Replied to Flip() Collection Between Model And Relations?

Okay, so if you want the count for users who have commented on a post, then say that in the original thread. When you say you want to flip the model, it indicates you want a relationship.

You mention $comment->user and then you mention $post, so make your mind up. I'm not a mind reader, I don't know if you have a different thread up or not.

You can either use the query builder and do a little funkiness with that, or the post relationship to do this, using withCount and distinct if necessary.

Activity icon

Replied to Flip() Collection Between Model And Relations?

User.php

public function comments()
{
        return $this->hasMany(Comment::class);
}
Activity icon

Replied to Flip() Collection Between Model And Relations?

I think what you want is another relationship, on the user model to the comment model.

You'd then access it like $user->comments

Apologies, on my phone.

Activity icon

Awarded Best Reply on Is It A Good Idea To Develop All Web Based Projects Using REST API

I do. But also note that GraphQL is used just as much now, which is not RESTful.

I personally haven't learned Graph yet, and for now, don't intend to. I find it requires a lot of work just to customize your json responses for your API.

In Laravel, REST is standard. Conforming to REST in Laravel, both route definitions and controller methods, makes developing applications even better.

I see some people conforming to REST, but then also having a controller with 10-15 methods. It just becomes messy.

Activity icon

Replied to Dusk LoginAs - Can't Get It To Work

I know Dusk extends a different TestCase, but does* it also provide methods from the Core TestCase class from Laravel? If so, you could try:

$this->withSession(['foo' => 'bar']);
Activity icon

Replied to Render Laravel Var In VueJS, QuillJS Editor

Haha. It happens to all of us bro. Sometimes we all don't see the simple shit.

Activity icon

Replied to Render Laravel Var In VueJS, QuillJS Editor

Does VueDevtools show the data being passed to the component? You should be able to dig deep into that component, and look for the content key, to see if it's set.

Whilst you're in the console, get the vm identifier (click on the component in vue devtools, and it should show something like $vm0 etc. And then use it in the console, and try to set the content manually, to see if it refreshes.

// along the lines of....
$vm0.form.body = 'some random content';
Activity icon

Replied to Render Laravel Var In VueJS, QuillJS Editor

Based on the package you're using, it has a :content prop for passing the data through. Try that. It's interesting as v-model should also pick it up according to the docs:

https://github.com/surmon-china/vue-quill-editor#ssr

Haven't worked with Vue in a while, but i'm pretty sure we used to have to set the form params in the mounted method when dealing with a prop, rather than directly assigning the value from the prop in data(). Could try that also

Activity icon

Awarded Best Reply on WithTrashed

Again, in the docs, but for the sake of resolving this thread:

When a model uses the SoftDeletes trait, the ->delete() method will change, and no longer permanently delete the record.

To permanently delete a record, you can use ->forceDelete()

Activity icon

Replied to What Are Your Next Steps After Learning The Tools With Laravel?

I have this exercise you can complete if you like. A friend of mine sent it to me a long time ago, so I just put it up on Github for others.

https://github.com/JayteeNZ/marvel-comics-training-exercise

You'll work with an external API, Vue and Laravel.

Activity icon

Replied to WithTrashed

Again, in the docs, but for the sake of resolving this thread:

When a model uses the SoftDeletes trait, the ->delete() method will change, and no longer permanently delete the record.

To permanently delete a record, you can use ->forceDelete()

Activity icon

Replied to WithTrashed

Yep.

Activity icon

Replied to WithTrashed

Still 2 years. Still isn't a good enough reason as to why you can't read the docs either. That should of been something you achieve within a couple of months.

The model itself is using SoftDeletes, so what it's doing is querying all models and including the ones that have been deleted. By default, soft deleted records are omitted from queries, unless you specify they should be included by using ->withTrashed().

Again, the section of the documentation covers this: https://laravel.com/docs/5.8/eloquent#soft-deleting

Activity icon

Replied to WithTrashed

@jlrdw Nope lol! I don't understand why it's so difficult to search/read documentation, especially after 2 years. You can literally search any method, or keyword on the Laravel docs, and it'll give you the result.

Activity icon

Replied to WithTrashed

Don't provide us a reference to Eloquent. Use that reference and stop being lazy, scroll down and you'll find the answer.

It literally states all these questions you ask, in the docs.

Nov
11
1 week ago
Activity icon

Started a new Conversation For Those Looking To Building An Application Regarding Esports/Games

I've just open-sourced my first project I built when learning Laravel almost 5 years ago. I've seen quite a few threads on Laracasts in the past with users who have similar projects, so I've decided to show you guys how I tackled this.

This does not apply to users who take no interest in this subject, however feel free to have a look. Read the read me.

For new developers in PHP / Laravel, this may be relevant to you, not knowing where to start when creating a project etc, and probably has the same thought processes as you. You can see all of the rights/wrongs I did when starting out, and I think it may be a good learning curve on how not to tackle certain problems.

https://github.com/JayteeNZ/esports-archived

Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

I have this project i've just published on Github, as I figured it's time to share my old work. My situation was slightly different as I wasn't aiming to sell games, I was aiming to provide tournament services.

Nevertheless, some of the code in the repository may be of relevance to you in the future, and how I first started out when building applications like this.

You can find it here: https://github.com/JayteeNZ/esports-archived

Activity icon

Replied to Is It A Good Thing To Have Many Textarea ?

@browniecoffee

You could tackle it in a different approach, and similar to how other applications have articles setup.

Use a Markdown or WYSIWYG editor would allows the ability to insert headings, and line breaks to act as "blocks".

Or, just create multiple articles per step. Kind of how a tutorial would be split up into parts.

Your approach is fine however. Don't be worried about it.

Activity icon

Replied to How To Unistall Package Which I've Already Installed ?

I'd be worried. @willvincent keeps a database log of all users who don't put any effort in to researching their own issues, and flags them. Each time he responds to a thread, he checks if the user exists ;)

I know who I'd have on the list, it'd be a long list too haha

Activity icon

Replied to Create Default Data When New Users Are Created

You can do it at the database level by chaining on ->default('value here') to the table definitions in your code above.

You'll still need to create the record when a user is created. To do this, you can either listen for the Login event, or look into the trait that is used on the registration controller, which provides a method that is called after a user is created. If you take the latter approach, you'll need to copy that method into the controller, not modify the trait.

Note that you're working with dates, and more specifically times, so you'll need to the appropriate time and format like: 00:00.

An alternative would be to use ->decimal() instead, to which you store it in hours, e.g: 8.5 = 8 and a half hours, but your calculations for determining the correct rates would need to be precise, as we only have 60minutes in an hour (which you think as being able to divide by 6), but an integer can be divided by 10, if you understand what I mean.

For time: once it hits 23:59 it'll reset back to 00:00 when using libraries like carbon for calculations.

With decimals, it's more accurate and common to what we would see in an HR database these days, but you'll need to actually calculate the exact overtime.

For an easier approach, store it in minutes (a bigInteger would suffice). No calculations would be required, and it'd be easy to convert into hours.

Activity icon

Replied to How To Insert A Row Automatically In Db

Look into Seeders and Factories, in conjunction with the --seed command.

The documentation includes all of this here:

Activity icon

Replied to Why Is Axios, Vue, Etc. Listed In Package.json Under DevDependencies?

It's worth noting the following too:

Both the package.json and composer.json files have a corresponding dev section for development dependencies, and a generic require section for production dependencies; however, they are often used opposite to each other.

With package.json, almost all packages you install will be included into devDependencies, as most of this will just be compiled for production. Running npm|yarn install {package} will place it into devDependencies by default I believe.

With composer.json, almost all packages will be pulled into require, as they're core files that need to run from the vendor folder. Only packages that are required for testing will be installed via require-dev.

Activity icon

Replied to When It's Too Much

You might be able to do something along the lines of this (may not work exactly), to clean up the methods that are testing for each required field:

Two options:

Option 1

Check if all fields fail, and check if all fields pass. Define the validation fields and messages you should expect

$this->post('api/register', [])
        ->assertJsonValidationErrors([
            'email' => [
                'Validation message that is returned when required',
                'Validation message that is returned when unique',
            ],
            'password' => [
                'Validation message ....',
            ],
            'username' => [
                'Validation message... required and unique',
                //
            ]
        ]);

Option 2

Extract out to a method:

protected function assertFieldRequired($field, $attributes = [])
{
    $this->post('api/register', $attributes)
        ->seeStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY)
        ->seeJsonStructure([$field]);
}

public function registration_require_a_unique_username()
{
    // for standard checking to see if required
    $this->assertFieldRequired('username');

    // for checking uniqueness
    $this->assertFieldRequired('username', new User(['username' => 'a username that is not unique']));        
}
Activity icon

Awarded Best Reply on Why Is Axios, Vue, Etc. Listed In Package.json Under DevDependencies?

When you deploy a project, and run npm run production, the files get compiled into the public folder into an app.css and app.js file, therefore, we no longer need to use them via the node_modules directory. Hence why they sit in the devDependencies. At least, that's my under standing of it.

When you removed them from your package.json, the compiled files were still in the public folder, so they were still available. If you were to remove them, then it would error as they're no longer defined.

EDIT: I'm back on the laptop now. Yeah, so the dependencies that are listed under devDependencies aren't packages that we'll run standalone. We use them to build other files, or to compile/bundle other packages.

This also applies to composer.json. Notice we have the same. We have core dependencies under "require", like the actual framework itself, because of course, we need the framework to run our application, but under "require-dev", we have things like the Exception Handler UI and PHPUnit. We won't use the UI, because of course, we want to send our exceptions somewhere else like a log file, or bugsnag, or another service, when in production. We also don't want to be able to freely run tests when in production, using PHPUnit. We do that when we're in the development environment.

Activity icon

Replied to Why Is Axios, Vue, Etc. Listed In Package.json Under DevDependencies?

When you deploy a project, and run npm run production, the files get compiled into the public folder into an app.css and app.js file, therefore, we no longer need to use them via the node_modules directory. Hence why they sit in the devDependencies. At least, that's my under standing of it.

When you removed them from your package.json, the compiled files were still in the public folder, so they were still available. If you were to remove them, then it would error as they're no longer defined.

EDIT: I'm back on the laptop now. Yeah, so the dependencies that are listed under devDependencies aren't packages that we'll run standalone. We use them to build other files, or to compile/bundle other packages.

This also applies to composer.json. Notice we have the same. We have core dependencies under "require", like the actual framework itself, because of course, we need the framework to run our application, but under "require-dev", we have things like the Exception Handler UI and PHPUnit. We won't use the UI, because of course, we want to send our exceptions somewhere else like a log file, or bugsnag, or another service, when in production. We also don't want to be able to freely run tests when in production, using PHPUnit. We do that when we're in the development environment.

Activity icon

Replied to Unable To JSON Encode Payload. Error Code: 5

You may get away with json encoding the data before you pass it to the job, and then decoding it in the handle method. It'll be encoded twice, but Laravel checks for any json errors, where as if you do it manually, you won't be, and it'll convert the characters

Activity icon

Replied to Check If Endpoint Exists

I'd follow @tray2 's advice.

You write it out, it'll fail, you make it pass by meeting it's requirements, then you refactor. Repeat this.

All you need to do is define that route, if that's good enough to make the test pass, then you leave it at that, until it fails again, and that route needs to do something.

Activity icon

Replied to Custom Certificate With Laravel Valet

@tykus Good man! Much better solution than mine.

Activity icon

Replied to Custom Certificate With Laravel Valet

Here's the Valet file responsible for securing a site. Based on this, you may need to create your own driver (see docs), or clone the repository, and modify this file to include your own.

https://github.com/laravel/valet/blob/master/cli/Valet/Site.php

Although, I would of thought the service you're trying to use would allow any certificate when in testing. What's the service you're using?

Activity icon

Replied to Class Google\AdsApi\AdWords\v201806\cm\CampaignService Does Not Exist

Based on the documentation for the package, that should work. So once you get your production account approved from google, you just set those credentials up, and that code should work out of the box to fetch real campaigns.

I'm sure you can setup some test campaigns on a test account, or it might provide fake data to work with.