JanakaDombawela

Senior Software Engineer at Ontomatrix Digital Marketing

Experience

1,050

1 Best Reply Awards

  • Member Since 11 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

3rd April, 2018

JanakaDombawela left a reply on HTML And PHP Tags Saved In DB, How To Show It On Blade? • 5 months ago

@serverus14 Please add the full code

26th March, 2018

JanakaDombawela started a new conversation Save Query On Db Listen Event • 5 months ago

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?

5th February, 2018

JanakaDombawela left a reply on V-for Not Working For Select Tag Options. • 7 months ago

Any update on this? Is this still an issue?

31st January, 2018

JanakaDombawela left a reply on Reactivity Is Lost Inside V-for • 7 months ago

@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? • 7 months ago

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?

30th January, 2018

JanakaDombawela left a reply on Reactivity Is Lost Inside V-for • 7 months ago

@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.

29th January, 2018

JanakaDombawela left a reply on Reactivity Is Lost Inside V-for • 7 months ago

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

JanakaDombawela started a new conversation Reactivity Is Lost Inside V-for • 7 months ago

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.

28th November, 2017

JanakaDombawela left a reply on SPA Tokens And Laravel • 9 months ago

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 • 9 months ago

JanakaDombawela left a reply on SPA Tokens And Laravel • 9 months ago

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 • 9 months ago

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.

16th November, 2017

JanakaDombawela started a new conversation Get JSON Response Instead Of Login Form With Passport • 10 months ago

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?

30th October, 2017

JanakaDombawela left a reply on Passport • 10 months ago

bump

26th October, 2017

JanakaDombawela left a reply on Wildcard Route • 10 months ago

@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.

18th October, 2017

JanakaDombawela started a new conversation For Loop And Axios • 11 months ago

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?

11th October, 2017

JanakaDombawela left a reply on How To Iterate Thorough A Vue Data Inside Mounted? • 11 months ago

@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? • 11 months ago

@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? • 11 months ago

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?

7th October, 2017

JanakaDombawela left a reply on Problem With Accessing Local Symbolic Link In Storage • 11 months ago

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

JanakaDombawela started a new conversation Problem With Accessing Local Symbolic Link In Storage • 11 months ago

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.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.