Alun

Alun

Member Since 11 Months Ago

Experience Points 1,650
Experience Level 1

3,350 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 13
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

17 Feb
4 months ago

Alun left a reply on Extending Vue SFC, Methods From Child Component Not Working

@EJDELMONICO - The thing about extending it is this way instead of using mixins is the capability of overriding the parent's methods, which don't happen whith the mixins. However, I think I know why is this happening: I'm extending from a component and then using the same component within the child, therefore the events on the parent always call to the parent's methods, nothing to do with the child. I changed the way to extending it and writing the template in the children (again) so I can use both, parent's and children's methods. The ugly thing here is the fact that I have to write the same template in the 3 components, but it's a minor issue if I can reuse the loginc

11 Feb
4 months ago

Alun started a new conversation Extending Vue SFC, Methods From Child Component Not Working

Hi there,

I have a base component which sometimes I need to extend with some extra functionality, they look like this:

// ParentComponent.vue
<template>
    <some-html>
        <more-html-stuff />
        <button type="button" class="btn" @click="debug()">Debug</button>
    </some-html>
</template>
<script>
export default {
    name: 'ParentComponent',
    props: {
        // some props
    },
    computed:{
        returnSomething(){
            return this.prop_X;
        }
    },
    methods: {
        // methods
        debug(){
            console.log('this is parent');
        }
    }
};
</script>

// Child_1.vue
<template>
    <parent-component v-bind="$props" />
</template>
<script>
import ParentComponent from './ParentComponent';
export default {
    name: 'ChildComponent',
    components: {ParentComponent},
    extends: ParentComponent,
    props: {
        another_property: {}
    },
    computed: {
        returnSomething(){
            return 'anotherThing';
        }
    },
    methods: {
        debug(){
            console.log('this is child');
        }
    }
};
</script>

By using ParentComponent as a component in the child, I can reutilize the template, however I think that's leading to an issue when I click the debug button and no matter what component I'm using, only the parent's method is being called.

Any orientation here please? Thank you all

08 Dec
6 months ago

Alun started a new conversation Passport Raising An Exception When CreateToken Is Called

Hi,

I've come to the situation in where I need both, a traditional login and an API login, so I decided to have a look to Laravel Passport. I had already the Laravel's Auth installed in my app, but to test the two of them coexisting I created a fresh project. First I installed the traditional login, and after I went for the Passport's. The idea was to generate a token when a user logs in, so I went with this code:

// HomeController.php
// Having the user logged in already:
public function index(){
    $user = Auth::user();
    $token = $user->createToken('Test token')->accessToken;
}

The method createToken() is raising an exception "Trying to get property of non-object", I debugged the process, and have found that, in the Eloquent's Builder, the where() method is getting passed "client-id" as second parameter, I'm not really sure, but the parameter's name is "$operator". "client-id" is what I defined in my AuthServiceProvider like so:

public function boot(){
    $this->registerPolicies();

    Passport::routes();
    Passport::personalAccessClientId('client-id');
}

I ran the install command right after installing the package and ran the migrations:

php artisan passport:install

Can it be considered a bug in the package because it's sending the wrong parameters, or am I doing something wrong?

Thank you

17 Nov
7 months ago

Alun left a reply on Dynamically Add Content To Bootstrap-vue Popover

In case someone wants to know, it was a nnoby error: I forgot to change " content="body" " for " v-if="my.var.popover" " in the <b-popover> tag. It's solved and working properly now

16 Nov
7 months ago

Alun started a new conversation Dynamically Add Content To Bootstrap-vue Popover

Hi, I'm migrating my project from jquery + bootstrap + vuejs to only vuejs + bootstrap-vue. I used to have a few popovers within the main app and in some components. The components' have been updated properly by changing the markdown to <b-btn></b-btn><b-popover></b-popover>, however the ones in the main app are experiencing struggles with it: they used to be shown depending on a variable and the title and content is loaded via Ajax. Now with the new markdown they never get shown. Here are the old and new codes:

old file.blade.php:

<button type="button" 
    id="my_popover"
    class="btn btn-lg"
    data-toggle="popover"
    data-container="body"
    :title="my.var.name"
    :data-content="my.var.description"
    v-if="my.var.popover">
    <i class="fa fa-question-circle"></i>
</button>

old app.js

new Vue({
    data: {
        my: {
            var: {
                name: null,
                description: null,
                popover: false
            }
        }
    },
    methods(){
        myFunction(){
            let url = '/my_url';
            axios.get(url).then(response => {
                let data = response.data;
                this.my.var.title = data.title;
                this.my.var.description = data.description;
                this.setPopup('var');
            }).catch(error => {
                console.error(error);
                console.error(error.message);
            });
        },
        setPopup(v){
            this.my[v].popover = true;
            let pop = '#'+v+'_popover';
            this.$nextTick(() => {
                $(pop).popover({
                    content: 'body',
                    trigger: 'hover',
                    placement: 'right'
                });
            });
        }
    }
});

new file.blade.php:

<b-popover target="my_popover" placement="right" 
    :title="my.var.name" 
    triggers="hover" 
    ref="popover"
    content="body"
    placement="right"
    :content="my.var.description">
</b-popover>
<b-btn id="my_popover" class="btn-default" variant="default" v-if="my.var.popover">
    <i class="fa fa-question-circle"></i>
</b-btn>

new app.js

new Vue({
    data: {
        my: {
            var: {
                name: null,
                description: null,
                popover: false
            }
        }
    },
    methods(){
        myFunction(){
            let url = '/my_url';
            axios.get(url).then(response => {
                let data = response.data;
                this.my.var.title = data.title;
                this.my.var.description = data.description;
                this.setPopup('var');
            }).catch(error => {
                console.error(error);
                console.error(error.message);
            });
        },
        setPopup(v){
            this.$nextTick(() => {
                this.my[v].popover = true;
            });
        }
    }
});

The result here is nothing: the popover never appears (as for the documentation, if the content is null, the popover will not show up, which is fair, but the content is binded to a variable that actuallt changes).

Is there a way to make this work with ajax?

Thanks

25 Jul
11 months ago

Alun left a reply on WherePivot Using The Word 'pivot' Instead Of The Actual Table

@bobbybouwmann thanks for the response. That's not exactle what I'm trying to get, but it's my fault, my explanation war completely wrong. So, the need is a row from table A depending on table B's id and matching some pivot's params. The raw SQL looks like this:

select t1.*
from t1, pivot
where pivot.id_t3 = :param1
and pivot.pivot_a <= :param2
and pivot.pivot_b >= :param2
and pivot.id_t1 = t1.id
and t1.fieldX = :param3

I know I can do it woth a raw query and it'd save me hours as I have it done already, but I want to learn a bit more about Eloquent. I tried to match pivot.id_t1 = t1.id, but could not get to the correct method / syntax.

Alun left a reply on WherePivot Using The Word 'pivot' Instead Of The Actual Table

@bobbybouwmann the thing is that I need to retrieve this table as well as it's relations, how could I call them all together in one method?

Alun started a new conversation WherePivot Using The Word 'pivot' Instead Of The Actual Table

Hi, I'm trying to make a M2M relation using a custom table with extra values. This values need to be queried so I can retrieve the proper relation. It loosk like this:

    -table_a
        -id_a
        -col1
        -col2
        -colN
    -table_b
        -id_b
        -col3
        -col4
        -colM
    -table_pivot
        -id_pivot
        -id_a
        -id_b
        -pivot_1
        -pivot_2
        -pivot_N

Now in my model A I'm trying to do this:

public function getByPivot($val){
    return $this 
        ->wherePivot('pivot_a', '<=', $val)
        ->wherePivot('pivot_b', '>=', $val)->get();
}

public function table_b(){
    return $this->belongsToMany(Table_B::class, 'table_pivot', 'id_a', 'id_b')
        ->withPivot(['pivot_a', 'pivot_b']);
}

The SQL I'm getting with this is as below:

select * from `table_a` where `pivot` = pivot_a and `pivot` = pivot_b

I don't know if this is an actual bug or I'm doing something wrong, but the SQL I want to achieve is like this:

select * from `table_a` where `pivot_a` <= val and `pivot_b` >= val

How can I?

Thanks

12 Jul
11 months ago

Alun left a reply on Bootstrap's Popover Dinamically

Thanks for the quick response. I tried to add this 'data-content' like so (bear in mind that it's my first Vue's app, still learning it):

<div class="col-md-6">
    {{ Form::customButton(__('button'), ['field'=>'myField', 'activate'=>'nextField', '@click'=>'getRandomData', 'data-content'=>'myVar.myField.description']) }}
</div>

However this way doesn't seem to work either, the "myVar.myField.description" var doesn't get evaluated when I inspect it on the DOM inspector. I'm pretty sure I'm missing something, but don't know what... Any clue please?

Thank you!

11 Jul
11 months ago

Alun started a new conversation Bootstrap's Popover Dinamically

I'm making a form in which every field depends on the previous one, so it is mostly made in ajax: when a button is clicked, I'm calling the server via axios to ger a random data, and then this button gets disabled, and the next one gets enabled to repeat and get new data depending on the fist random data.

One of the fields I'm getting is a description ment to be in a popover, but of course it cannot be set at creation time as it's comig from the server later on. The code I'm trying to use unsuccessfully is as follows:

    <!-- template.blade.php -->
    <!-- there are several fields like this one -->
    <div class="col-md-3">
        <div id="myField_container" class="row">
            <div class="col-md-6">
                {{ Form::label('myField', __('myField')) }}
            </div>
            <div class="col-md-6">
                {{ Form::customButton(__('button'), ['field'=>'myField', 'activate'=>'nextField', '@click'=>'getRandomData']) }}
            </div>
            <div class="col-md-6">
                {{ Form::text('myField', old('myField'), ['class'=>'form-control', 'disabled'=>'disabled', 'v-model'=>'myVar.myField.name']) }}
            </div>
        </div>
    </div>
    // the_js_file.js
    app = new Vue({
        data: {
            myVar: {
                myField: {
                    id: null,
                    name: null,
                    description: null
                }
            }
        }
        methods: {
            setPopup(el, field){
               $(el)
                   .html('<i class="fa fa-question-circle"></i>')
                   .prop('title', this.myVar[field]['name'])
                   .data('toggle', 'popover')
                   .popover({
                       content: this.myVar[field]['descripcion']
                   });
            },
            getRandomData(e){
                var rn = this.getRandomNumber();
                var url = this.url('getRandomData?randomNumber='+rn);
                
                axios.get(url).then(response => {
                    var data = response.data[0];

                    // this sets the properties properly
                    this.setProps(data, 'myField', ['id', 'name', 'description']);

                    // but this one is failling
                    this.setPopup(e.target, 'myField');
                    this.swapToNext(e);
                }).catch(error => {
                    console.log('error: ');
                    console.log(error);
                });
            }
        }
    });

As I've read, DOM cannot be modified in runtime because it's not evaluated by Vue. In this case, the idea is to change the button's content, which is happening, via JQuery's .html(), and add the popover to this "new" element.

Is there any way to achieve this?

Thank you all.

05 Jul
11 months ago

Alun started a new conversation Accessor Not Working With Chunk()?

I'm new in Laravel, and checking this forum very often to solve lots of issues while learning. So I tried to create an accessor in one of my models to basically convert the colum "title" into a slug. I followed several answers from this forum, but none of them seems to work for me, basically the method I created doesn't get executed at all. Here's the code:

// app/Http/Models/Competence.php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;
use App\Http\Helpers\StringHelper;

class Competencia extends Model {
    
    protected $table = 't_competences';
    
    public $timestamps = false;
    
    protected $fillable = ['name', 'other_non_relevant_fields'];
    
    protected $appends = ['slug'];
    
    // ...
    
    public function getSlugAttribute(){
        return (new StringHelper())->slug($this->nombre);
    }
    
    // ...
}
// app/resources/parts/competences.blade.php

@foreach($competence->chunk(2) as $c)
    @section('vars')
        <!-- Definition of some bars, I know it's a bad practice, but it's a need -->
        $classname = 'my-classes'
    @endsection
    <div id="{{ $c->slug }} class="{{ $classname }}>
        <!-- some more code -->
    </div>
@endforeach 

What I don't get to understand is why, if I remove the "chunk(2)" method, which I need so I can split the collection in two columns, the accessor works, but with it I get the exception "Property [slug] does not exist on this collection instance.".

Any idea of why this happens or any way to split this collection?

Thanks very much.