JanakaDombawela

JanakaDombawela

Senior Software Engineer at Ontomatrix Digital Marketing

Matale

Member Since 1 Year Ago

Experience Points 1,050
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 1
Best Answer
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.

03 Apr
8 months ago
26 Mar
8 months ago

JanakaDombawela started a new conversation Save Query On Db Listen Event

I have a requirement that I need to save each and every query executed by the laravel program. I have created following listener in boot method of app/Http/Providers/AppServiceProvider

    public function boot()
    {
        DB::listen(
            function ($query) {
                $query_binding = '';
                foreach ($query->bindings as $binding) {
                    $query_binding .= $binding . ', ';
                }
                QueryLog::create([
                    'sql' => $query->sql,
                    'bindings' => $query_binding,
                    'time' => $query->time
                ]);
            }
        );
    }

I get following error:

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'bindings' at row 1 (SQL: insert into query_log (sql, bindings, time, updated_at, created_at) values (insert into query_log (sql, bindings, time, updated_at, created_at) values (insert into query_log (sql, bindings, time, updated_at, created_at) values (0.17, 2018-03-26 07:27:36, 2018-03-26 07:27:36, ?, ?), insert into query_log (sql, bindings, time, updated_at, created_at) values (?, ?, ?, ?, ?), select * from users where id = ? limit 1, 3, , 2.63, 2018-03-26 07:27:36, 2018-03-26 07:27:36, , 0.23, 2018-03-26 07:27:36, 2018-03-26 07:27:36, , 0.17, 2018-03-26 07:27:36, 2018-03-26 07:27:36, , ?, ?, ?, ?), ?, ?, ?, ?))

I believe this is due to the DB::listen listen to its own query and try to save it creates a infinite loop.

How to exclude the saving query of DB::listen and save all the other queries?

05 Feb
10 months ago

JanakaDombawela left a reply on V-for Not Working For Select Tag Options.

Any update on this? Is this still an issue?

31 Jan
10 months ago

JanakaDombawela left a reply on Reactivity Is Lost Inside V-for

@arukomp I used this as:

this.$set(selected_user[0], 'active', true);

and it worked! Thanks a lot!

JanakaDombawela left a reply on Why Laravel Not Returning Eloquent Model Data As Integer But Returns String?

Is there any other solution than casting in the model? If the database is big casting all fields in all models is not practical solution?

30 Jan
10 months ago

JanakaDombawela left a reply on Reactivity Is Lost Inside V-for

@arukomp Thanks for the first suggestion. I have removed filter from the funtion. And for the question, this.users have active property initially set to false.

29 Jan
10 months ago

JanakaDombawela left a reply on Reactivity Is Lost Inside V-for

@bobbybouwmann Thanks. I tried the $set method but it gave me undefined method.

JanakaDombawela started a new conversation Reactivity Is Lost Inside V-for

I have following scenario.

I have users object which has active field with boolean values.

Initially the HTML is loaded with users as follows:

<tr v-for="user in users">
                                    <td class="col-1">@{{user.name}}</td>
                                    <td class="col-2"><a href="#" @click="setActive(user.id,$event)">
                                            <img class="svg Green" :class="{'active':user.active}"
                                                 src="image.jpg"
                                                 alt="info" width="33" height="33"></a></td>
                                </tr>

I have following Vue js code:

var vue_users = new Vue({
            data: data,
            el: '#users',
            methods: {
                setActive: function (user_id, event) {
                    event.preventDefault();
                    var filtered_user = this.users.filter(function (user) {
                        return user.id == user_id;
                    });

                    var $this = this;

                    axios.post('ajax-url'}', {
                        user_id: filtered_user[0].id
                    })
                        .then(function (response) {
                            if (response.data.status == 'success') {
                                $this.resetButtons(user_id);
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                        });
                },
                resetButtons: function (user_id) {
                    var selected_user = this.users.filter(function (user) {
                        return user.id == user_id;
                    });

                        selected_user[0].active = true;
                }
            }
        });

The problem is this updates the user object, but changes does not showing in the DOM. Can anyone suggest what is the wrong with this code? Help is appreciated. Thanks.

28 Nov
1 year ago

JanakaDombawela left a reply on SPA Tokens And Laravel

I'm not clear about the internal Vue - Laravel relationship, if your page routes are served by laravel then everything should work fine in web routing, you don't need any api authenication. But if your page routes are handled by vue, then the problem is there is no session cookie in your client side app, so you need api authentication no matter if it is internal or not.

JanakaDombawela left a reply on SPA Tokens And Laravel

First you need to deploy keys with php artisan passport:keys Then you need to login a user via oauth/token with

{
    "client_id":"client_id",
    "client_secret":"client_secret",
    "grant_type":"password",
    "username":"email/username",
    "password":"password",
    "scope":"*"
}

Then it will return a access token, which you need to add as a bearer token. Have you tried that?

JanakaDombawela left a reply on SPA Tokens And Laravel

If you are using web routes, that means you are using sessions for authentication, which you don't on a SPA. You need to install Passport and create oauth authentication or any other token based stateless authentication method to constantly keep logged in to the laravel application.

16 Nov
1 year ago

JanakaDombawela started a new conversation Get JSON Response Instead Of Login Form With Passport

I have successfully installed passport and started to code an API. When I guard my routes with passport, if not logged in, I get login form as response.

in routes/api.php,

Route::middleware('auth:api')->get('/', '[email protected]');

How do I get JSON response instead of login form HTML?

30 Oct
1 year ago

JanakaDombawela left a reply on Passport

bump

26 Oct
1 year ago

JanakaDombawela left a reply on Wildcard Route

@WeeHong I think not.

So, I don't need to create new route again and again whenever I created a new category.

Then you have to create new case again and again whenever you create a new category. I think your approach is difficult. Try to parametrize a layout with the values from urls rather than create a layout for each url.

18 Oct
1 year ago

JanakaDombawela started a new conversation For Loop And Axios

I have following scenario where I have to call a third party API for each item in Vue object. I call it as follows:

var $this = this;
for (var i = 0; i < $this.items.length; i++) {
  axios.get('https://thirdpartyapi.com/api/' + $this.items[i].somevalue)
    .then(function(response) {
      if (somevarialble.toLowerCase() == response.data[0].itemValue.toLowerCase()) {
        $this.filteredItems.push($this.items[i]);
      }
    })
    .catch(function(error) {
      console.log(error);
    });
}

But I always get i as 62(which is the last one). How to pass i inside axios?

11 Oct
1 year ago

JanakaDombawela left a reply on How To Iterate Thorough A Vue Data Inside Mounted?

@Yeman: I get TypeError: this.cart.forEach is not a function

JanakaDombawela left a reply on How To Iterate Thorough A Vue Data Inside Mounted?

@Yeman I get TypeError: this.items.forEach is not a function

JanakaDombawela started a new conversation How To Iterate Thorough A Vue Data Inside Mounted?

Hello,

I have following setup.

var data = {
    items: [],
    total: 0
};

var cart = new Vue({
    el: '#root',
    data: data,
    mounted: function () {
        var $this = this;
        axios.get(vue_items_url).then(function (response) {
            $this.items = response.data;
            var total = 0;
            for (var i = 0; i < $this.items.length; i++) {
                total += $this.items[i].price * $this.items[i].qty;
            }
            $this.total = total;
        }).catch(function (error) {
            console.log(error);
        });
    }
});

This does not iterate through items array. How to iterate through Vue object? Is there any proper way?

07 Oct
1 year ago

JanakaDombawela left a reply on Problem With Accessing Local Symbolic Link In Storage

@Dry7 This outputs: /storage/2017/10/file.txt but still 404 :(

JanakaDombawela started a new conversation Problem With Accessing Local Symbolic Link In Storage

Hi,

I created my symbolic link with php artisan storage:link

I save my files in following function:

Storage::put( Carbon::now()->format( 'Y' ) . '/' . Carbon::now()->format( 'm' ), 'file.txt' );

My config/filesystems.php configurations:

'local' => [
            'driver' => 'local',
            'root' => storage_path('uploads'),
        ],

The files are saved in the storage/uploads/2017/10 directory, which is what I want.

I access them as follows:

{{URL::to('storage/2017/10/file.txt')}}

which outputs: http://localhost/mysite/public/storage/2017/10/file.txt and it gives 404.

When I try to enter http://localhost/mysite/public/storage it shows empty directory, not a 404.

Can you guys give any suggestions or ideas? Help is appreciated. Thanks.