willjohnathan

willjohnathan

Member Since 2 Years Ago

Experience Points
34,820
Total
Experience

180 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
340
Lessons
Completed
Best Reply Awards
0
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 7
34,820 XP
Nov
05
1 week ago
Activity icon

Replied to Laravel - Access Denied For User

using @Snapey advice, putting quotes around password fixed it for me.

Oct
19
4 weeks ago
Activity icon

Started a new Conversation Temporal Database Design, SoftDeletes Or Custom Field

For a temporal datase design (i.e. pricing table, with "effective dates") , do you use softdeletes and then utilize the created_at / deleted_at fields or do you use custom fields (i.e. starting_at/ created_at and then end_at)?

Seems like softDeletes could achieve the desired result, but then again there might be unnecessary overhead with having to query the withTrashed and it might not be as clear as just pulling the records and then filtering based on effective dates.

May
28
5 months ago
Activity icon

Replied to Best Schema For Comments Table Which Has Users And Visitors Comments

Seems fine to me... You could create a "visitor" table and store their info with a key in their cache so it could remember them and then do a polymorphic relation to where it could be App\Visitors or App\Users in the "subject_type" field and then the visitor_id/user_id in the "subject_id" field... but I think that might be overkill compared to what you have now, if it is working ok for you.

Activity icon

Replied to Undefined Property:

your not using $var though, and you are also not using $child... maybe you mean to do this:

foreach($var as $child){
    $total += $child->children()->events()->sum('price');
}

a little hard to tell with what you posted but something like that

May
25
5 months ago
Activity icon

Replied to Help With Booking System Timezone Offsets

@TIMGAVIN - You need a full date... which is what a timestamp is. Laravel stores the time in the db according to the app variable: config('app.timezone') . I would recomend that you store your datetime in utc; but if not you can always do something like this (assuming "reserved" is a timestamp in your db):

Reservation.php (or whatever your model is called)

    public function getReservedDatAttribute()
    {
        return $this
            ->reserved
            ->timezone(config('app.timezone'))
            ->tz($value)
            ->dayOfWeek;
    }

    public function getReservedHourAttribute()
    {
        return $this
            ->reserved
            ->timezone(config('app.timezone'))
            ->tz($value)
            ->format('hh:mm:ss');
    }

This will add the reserved_day and reserved_hour attributes to a model in the users timezone. You might need to take a slightly different approach (maybe setAttribute instead of getAttribute) depending on how you get the users timezone.

Activity icon

Replied to Help With Booking System Timezone Offsets

I would just store it as one value, a timestamp ie (reserved). Then your server-side logic can determine reserved_day and reserved_time off of the timestamp as well as handle the timezone across different days correctly.

As far as which time to display, is this a virtual appointment (meaning they will be in their timezone for this appointment)? If so then I would absolutely use the timezone offset. If they will be traveling to where the appointment is, then I would use the local time for that location.

May
24
5 months ago
Activity icon

Replied to Choose Whether To Keep The Result Of A Calculation As A Column In A Database Table

right... you wouldnt decrement your qty_remaining... you would modify your qty_in_hand, then your qty_remaining would automatically be calculated. I am not sure you can use decrement, but you could do this on your model:

public function setQtyRemainingAttribute($value)
{
    $this->attributes['qty_in_hand'] = $this->qty_in_hand + $value;
}

then in your controller:

$remaining = $sub_job->qty_remaining - $request->dispatch_item_qty[$sub_job->id];
$sub_job->qty_remaining = $remaining;
$sub_job->save();

You can get creative to do it in whatever sytnax you want to fit your needs.

Activity icon

Replied to Multiple Indexes Slowing Down Query

I always thought an index like his composite index would cover the following searches:

(col1), (col1, col2), (col1, col2, col3)

Activity icon

Replied to Laravel HasOne() Relationship

@STAUDENMEIR - I disagree with Taylor about not being useful... I understand if it adds too much complexity / maintanence to not be worht supporting. But I have had several instances where I have had a hasOne()->latest() relationship where I had to go back and refactor it to not crash as the database grew.

Activity icon

Replied to Choose Whether To Keep The Result Of A Calculation As A Column In A Database Table

My mistake, you have to use it on the collection instead of the query. For instance:

$shortage = SubJob::all()->where('qty_remaining',  '<', 10)->all();

That might not be ideal if you have a lot of records and you need to query based on it. It would still be my recomendation unless you start running into memory issues.

I would recommend something like this then (this would be added to SubJob.php):

protected static function boot() {
    parent::boot();

    static::saving(function($model){
        $model->qty_remaining = $model->qty - $model->qty_in_hand;
    }); 
}
May
23
5 months ago
Activity icon

Replied to Data Shows In Console, But Not In The View

@MUSHOOD - the way I wrote it, you don't have to reassign "this"; and based on @maverickchan 's response, I guess you don't have to reassign "this" the way you wrote it either. I know with this method I would have to:

const vm = this;
            axios.get('./api/admin')
            .then(function(data){
            vm.clients = response.data.clients);
            });
Activity icon

Replied to Check In Controller If Url Exists?

No. Your coin will always be set because you are defining it. It might return an empty collection though.

So something like this:

if($coin->isEmpty()) return abort(404);
Activity icon

Replied to Laravel Strange SQL Query Builded

Ok, that is why you are getting the ' ' in your IN . It is looking at all messagetypes that belong to that user and they have some with no product ID's / order ID's; so it will use the values of the fields (null) to look up the relation. I don't think that should mess anything up though because you won't have a Null or ' ' id on that table so it won't return anything.

Activity icon

Replied to INVOICE NUMBER IS NOT INCREMENT

@SNAPEY - I usually prefer to put a getAttribute on the model, that way I don't have to build it in the view and it is accessible in all views. However the one downside to this is that if you change your prefix in the future but still need to reference the older invoice with its original invoice number after the change is made, but then I guess you could always put a date in the getAttribute with different logic depending on the date.

Activity icon

Replied to Laravel Strange SQL Query Builded

Do you have messages_involved records with no product or order id's?

May
22
5 months ago
Activity icon

Replied to Authorise In Controller, FormRequest

you are calling $this->authorize() inside of your authorize method, so you have an endless loop.

Activity icon

Replied to Which Editor Do You Use To Work?

VS Code. I used sublime previously but didn't like not having the terminal in the editor. Also, all the syantax checking out of the box (or maybe extensions I installed as soon I started using it) that I didn't have with Sublime. Sometimes it is a little "buggy" though.

Also, i do a lot of python coding as well which has kept me from trying phpstorm

Activity icon

Replied to Choose Whether To Keep The Result Of A Calculation As A Column In A Database Table

if it is something I need to access often, i will often put the following on my model:

protected appends = ['qty_remaining'];

public function getQtyRemainingAtttribute(){
    return $this->qty - $this->qty_in_hand; 
}

then you can access just like it is on the database but not actually have it on the database ie.

    $shortage = Model::where('qty_remaining',  '<', 10)->get();

I usually avoid calculation fields on my tables as you have to make sure it is updated on all your updates / saves.

Activity icon

Replied to Data Shows In Console, But Not In The View

are you using the vuejs chrome extension so that you can see the vuejs variables. I doubt the

.then(response => this.clients = response.data.data);

is actually setting your clients variable properly. I get confused with the es6 syntax as far as assigning and sometimes have to put a breakpoint (dev tools source) at that line and inspect it or do a console.log(response) to see the proper format for accessing the needed data.

maybe:

.then(({data}) => {
    this.clients = data.clients;
});
Activity icon

Replied to Best Autocomplete For Laravel Projects With MySQL Backend

I recommend you install this chrome extension, it will show you what your vue variables are... My guess would be that your are not accessing the return data correctly in the callback, but hard to tell without looking at your code.

https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd?hl=en

Activity icon

Replied to How To Duplicate Value Validation In Laravel

maybe your validation isn't getting triggered, is your required working? If so, is your table correct, if it is job_titles, then I usually reference it as jobTitles, not sure how picky Laravel is about that though. Also don't think you have to add the column if it is the same as the key although that shouldn't cause an error.

May
21
5 months ago
Activity icon

Replied to Best Autocomplete For Laravel Projects With MySQL Backend

ok... why is it redirecting you? you are making an ajax call to a route that redirects you (probably meaning the auth user does not have access to view this resource so I am going to redirect you home)??? If that is what you want, you can do a $request->expectsJson() check on the controller before the redirect and send an appropriate resonse. Then you would want to check for the response in your ajax callback and have it redirect you back home.

OR if you want it to provide actual user data and not redirect you, make it so that visiting that link (http://newapp.test/api/user) outputs json of the users instead of redirecting you when you visit it in the browser.

You can go back afterwards and clean it up so that it redirects you if you are not doing an ajax call. But that is the root of your problem right now.

Activity icon

Replied to Best Autocomplete For Laravel Projects With MySQL Backend

What do you get when you navigate here:

http://newapp.test/api/user

This should be an error and the reason for your console error

Activity icon

Replied to Best Autocomplete For Laravel Projects With MySQL Backend

@WALLYJ - No... check the network tab in the developer console. You are getting a bad response from "http://newapp.test/api/user". Your vue component is making this request and getting a bad response from your server. You should also be able to paste the url in your get request into the web browser address bar and see a "Laravel" error.

Activity icon

Replied to Best Autocomplete For Laravel Projects With MySQL Backend

@WALLYJ - This error isn't related to vue... It is a server side error. Maybe your authentication has failed due to not being logged in? You still have access to all your Auth & Auth::user() data on the server side when doing an ajax request so you shouldn't be getting any additional errors, in case that is what you are thinking.

Activity icon

Replied to Best Autocomplete For Laravel Projects With MySQL Backend

@WALLYJ - yes. You can add inline-template to your tag and you you can use both blade & vue variables and you wouldn't have a "template" tag in you vue component.

In the example I provided your vue component would look like this and it should work:

<script>
    export default {
    props = ['clients']
    }
</script>
Activity icon

Replied to Best Autocomplete For Laravel Projects With MySQL Backend

There are a lot of ways to handle it. I think the simplest / quickest for at least getting started would be to either leave the auth in the blade or pass the auth checks / user values as props to the component. You can also create a global user js variable such as:

window.App = {!! json_encode([
            'user' => Auth::user(),
            'signedIn' => Auth::check()
        ]) !!};
Activity icon

Replied to Best Autocomplete For Laravel Projects With MySQL Backend

It is pretty easy to mix the two. I do it all the time until I decide I need complete reactivity to changing data. Something like this is what I do when quickly incorporating vue into an already working blade file:

@if ($user->isAdmin())
    <admin inline-template :clients="{{$clients}}">
        <div>
            <div v-for="client in clients" v-text="client.name"></div>
        </div>
    </admin>
@endif

This series has some great videos of going from fully blade to a little Vue to complete Vue once the need arises: https://laracasts.com/series/lets-build-a-forum-with-laravel