v0sn

v0sn

Member Since 11 Months Ago

Experience Points 450
Experience Level 1

4,550 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 1
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.

09 Dec
7 months ago

v0sn started a new conversation Relationships Between 3 Tables

Hello,

i have the following tables

messages
- id
- user_id
- message

user
- id

likes
- id
- message_id
- user_id

User Model

public function messages()
{
return $this->hasMany(Message::class);
}

Message Model

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function likes()
    {
        return $this->hasMany(Like::class);
    }

Like Model

    public function user()
    {
        return $this->belongsTo(User::class);
    }

So an user can post messages, and these messages can be liked.. am i doing the relationships right? is there a better way?

thanks

25 Nov
7 months ago

v0sn started a new conversation Vue Good Table Problem With Data From Get Request

hello, so i am trying to use my data which i get from the following route with the vue-good-table thingy

Route::get('/complaints/index', function() {
    return App\Complaint::with('user')->latest()->get();
});

in my index.vue

export default {
    data() {
        return {
            searchTerm: '',
            complaints: [],
            columns: [{
                    label: 'Ordernumber',
                    field: 'ordernumber',
                },
                {
                    label: 'City',
                    field: 'city',
                }
            ],
            rows: complaints,
        }
    },

    created() {
        axios.get('/complaints/index')
            .then(({
                data
            }) => this.complaints = data);
    }
}

the rows: complaints isnt working

error:


[Vue warn]: Error in render: "TypeError: Invalid attempt to spread non-iterable instance"

Maybe someone can explain that to me.. i think its because of the relations hasMany & belongsTo i have in my Complaint Model

    public function items()
    {
        return $this->hasMany(Item::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

thanks and sorry for my bad english

29 Aug
10 months ago

v0sn left a reply on Custom Blade Directive For Checking Date Diff

Blade::directive('test', function($arguments) {
    list($current_date, $date) = explode(',',str_replace(['(',')',' ', "'"], '', $arguments));

    return "<?php echo({$date}->diffInDays({$current_date})); ?>";
});

Putting curly braces around my variables fixxed the problem, i saw this in the custom blade directive for @set which i just copied from someone else and tried it out..

I don't actually know why this fixxed my problem, could someone explain me this?

v0sn left a reply on Custom Blade Directive For Checking Date Diff

Blade::directive('test', function($arguments) {
    list($current_date, $date) = explode(',',str_replace(['(',')',' ', "'"], '', $arguments));

    return "<?php echo($date->diffInDays($current_date));
});

This should simply return the difference between the 2 given dates

@set($current_date, Carbon::now())

This is how i set $current_date using another Blade directive

@test($current_date, $complaint->created_at)

This is how i call the test directive

Im getting the following error

Trying to get property 'diffInDays' of non-object

What i dont understand is: if if put the following code in my view, it gives me the difference, and its simply the same as the blade directive above

@php
    echo($complaint->created_at->diffInDays($current_date))
@endphp

I even put the dates in the protected_dates field in my Complaint Model.. but i dont think thats the problem here.

thanks in advance!

v0sn left a reply on Custom Blade Directive For Checking Date Diff

@Snapey ohhhhh, that was what i was doing wrong, i totally know what you mean! I'll try to get it to work now :- )

v0sn left a reply on Custom Blade Directive For Checking Date Diff

@tykus using it in the boot method of AppServiceProvider.php

v0sn left a reply on Custom Blade Directive For Checking Date Diff

Hello @Cronix,

sorry for the late reply..

I think the problem is something else, if i do a dd(); on $date in my custom blade directive it returns me the following: ´´´"$complaint->created_at"´´´ instead of the actual date.. why does this happen? am i missing something here?

24 Aug
10 months ago

v0sn started a new conversation Custom Blade Directive For Checking Date Diff

Hi guys,

i am trying to create my very first own blade directive, i want this blade directive to check the difference between a given date and todays date.

Heres what i tried:

        Blade::directive('deadline', function ($date) {
            $current_date = new \DateTime('now');

            if ($date->diffInDays($current_date) >= 7 ) {
                return "class='deadline'";
            }

        });

This is giving me the error:

Call to a member function diffInDays() on string

What am i doing wrong?

14 Aug
11 months ago

v0sn left a reply on Appending Params To A Form Request

my fix for now is:

@if(isset($_GET['q']))
    <input type="hidden" value="{{ $_GET['q'] }}" name="q" id="q">
@endif

But isn't there a nicer way?

v0sn started a new conversation Appending Params To A Form Request

Hello guys,

so i have a table with users and i've added some filters with local scopes

User.php

    public function scopeSearch($query, $search)
    {
        if (isset($search)) {
            return $query->where('id', 'like', '%' . $search . '%')->orWhere('name', 'like', '%' . $search . '%')->orWhere('email', 'like', '%' . $search . '%');
        }

        return $query;
    }

    public function scopeSelection($query, $selection)
    {
        if (isset($selection)) {
            switch ($selection) {
                case 1:
                    return $query->withTrashed();
                    break;
                case 2:
                    return $query;
                    break;
                case 3:
                    return $query->onlyTrashed();
                    break;
            }
        }
    }

    public function scopeAmount($query, $amount)
    {
        if (isset($amount)) {
            return $query->paginate($amount);
        }

        return $query->paginate(10);
    }

In my UsersController @ index im calling these filters like this

$users = User::search($request->q)->selection($request->selection)->amount($request->amount);

And in my index.blade.php i have to forms, one for the search field and one for the selection and amount (2 selects)

        <form action="{{ route('users.index') }}" type="get">
            <input class="uk-input uk-width-medium uk-border-rounded uk-box-shadow-small" id="q" name="q" value="{{ isset($_GET['q']) ? $_GET['q'] : "" }}" type="search" placeholder="Suche">
        </form>
                {{-- Form --}}
                <form action="{{ route('users.index') }}" method="GET">

                    {{-- Grid --}}
                    <div uk-grid>

                        {{-- Anzahl --}}
                        <div class="uk-width-1-3">
                            <span>Anzahl</span>
                        </div>
                        <div class="uk-width-2-3">
                            <select class="uk-select" name="amount" id="amount">
                                <option {{ (isset($_GET['amount']) && $_GET['amount'] == 10) ? 'selected' : "" }} value="10">10</option>
                                <option {{ (isset($_GET['amount']) && $_GET['amount'] == 25) ? 'selected' : "" }} value="25">25</option>
                                <option {{ (isset($_GET['amount']) && $_GET['amount'] == 50) ? 'selected' : "" }} value="50">50</option>
                            </select>
                        </div>
                        {{-- /Anzahl --}}

                        {{-- HR --}}
                        <div class="uk-width-1-1"><hr/></div>
                        {{-- /HR --}}

                        {{-- Auswahl --}}
                        <div class="uk-width-1-3">
                            <span>Auswahl</span>
                        </div>
                        <div class="uk-width-2-3">
                            <select class="uk-select" name="selection" id="selection">
                                <option {{ (isset($_GET['selection']) && $_GET['amount'] == 1) ? 'selected' : "" }} value="1">Aktiv</option>
                                <option {{ (isset($_GET['selection']) && $_GET['amount'] == 2) ? 'selected' : "" }} value="2">Inaktiv</option>
                            </select>
                        </div>
                        {{-- /Auswahl --}}

                        {{-- Button --}}
                        <div class="uk-width-1-1">
                            <button class="uk-button uk-button-link uk-text-muted uk-align-right" type="submit"><i class="fas fa-sync-alt"></i></button>
                        </div>
                        {{-- /Button --}}

                    </div>
                    {{-- /Grid --}}

                </form>
                {{-- /Form --}}

For design reasons i cant but them in one form field, now im struggling to append the params to each form. For example when i have set filters for amount and selection the url looks like this

http://localhost/?selection=2&amount=25

But when i then search something with the search field these 2 params will get removed (selection & amount) and the url will look like this

http://localhost/?q=name

How can i append the params to each form submission?

I hope you guys know what i mean, my english isn't the best i know..

Thanks in advance!

10 Aug
11 months ago

v0sn left a reply on Laravel Search Delete

@evripidesk whats your action and whats your method? You still need to put "method='POST'" to your even tho you are spoofing the methos afterwards

v0sn left a reply on Laravel Search Delete

@evripidesk can you post your current code? Do you use a button inside the form? It won't work with an "a" element

v0sn left a reply on Laravel Search Delete

@evripidesk yea thats right, then you just have to do the form right with the spoofed method and the csrf token & dont forget the $id

v0sn left a reply on Laravel Search Delete

Route '''Route::delete('something/{id}', '[email protected]')->name('something.destroy');''' you need that id here

Form '''

@method('DELETE') @csrf '''
09 Aug
11 months ago

v0sn started a new conversation I Feel Like I Misunderstood Routing

Hello Community,

so i've been coding with laravel for a few weeks now, but i still feel like i somehow misunderstood routing.

example: Route::view('/password', 'changePassword')->name('changePasswordView')->middleware('auth');

Route::get('/password/change', '[email protected]')->name('changePassword')->middleware('auth');

As you can see in the example above, i have a route for the change password page (view) And then i have a route for the change password action(?)

I feel like this isn't the right way to do. I do this very often, and i really haveing trouble finding names for those routes then.

Another example would be: Route::view('create', 'pages/admin/users/create')->name('view.create'); Route::post('create', '[email protected]')->name('user.create');

Here i tried to give the routes better names.. but still.. i don't know if im doing this right..

i would really appreciate if some of you guys could give me some tips

Cheers