How to pass parameters into the Vue JS function

Well, if you have doubt that, how to pass parametter in Vue JS function, here is the tips for you to do that.

Apply in VueJS

In you view,

<ul v-for="users in user">
  <li>
    <a href="#" v-on:click="showUser(user.id)">@{{ user.name }}</a>
  </li>
</ul>

Continue reading "How to pass parameters into the Vue JS function"

How to pass parameters into the Vue JS function

How to Use Typeahead (Auto-Complete) with HTML

If you are planning to use Auto-Complete field in your html, I believe, Typeahead is your first choose. Its very very flexible, where you can just use Typeahead.js library to use that.

Imagine that, you have a country list that you want to display in text field in html with auto-complete way. Let’s do this.

Continue reading "How to Use Typeahead (Auto-Complete) with HTML"

How to Use Typeahead (Auto-Complete) with HTML

Laravel show relationships method if it is not empty

One of the cool advantage of using laravel is relationships. Now imagine that you have a relationships between Post and Comment tables. A post has many comments. Now I will show you how to load posts which has comments only.

$allPosts = Posts::has('comments')->where('user_id', Auth::user->id())->with('comments')->get();

Continue reading "Laravel show relationships method if it is not empty"

Laravel show relationships method if it is not empty

Replace multiple items from a text string in PHP

If you want to find and replace more than one item from a string, you can follow the following techniques-

Let’s think of it, this our our text where we need to change the words java jsp and python words by php laravel and wordpress.

$phrase  = "Lets learn java, jsp, and python every day.";
$old = array("java", "jsp", "python");
$new   = array("php", "laravel", "wordpress");

Continue reading "Replace multiple items from a text string in PHP"

Replace multiple items from a text string in PHP

How to use IncludeWhen directive in Laravel blade?

One of the new addition of Larave directive is includeWhen directive in Laravel blade. Let’s see, how to use that.

Imagine that, you need to include a protected notice for aunthenticate user. In normal procedure, we check-

@if(Auth::user())
    //current user is auntehticated
    @include('notice')  //include notice page
@endif

It works fine. However, the whole things, you can do in more easier way. Let’s do that-

@includeWhen(Auth::user(), 'notice')

It’s cool, isn’t it?

Continue reading "How to use IncludeWhen directive in Laravel blade?"

How to use IncludeWhen directive in Laravel blade?

How to print html code in VueJS

If you want to print HTML code in VueJS, you can follow this post. Imagine that, you have a html page where you need to print html output from VueJS.

Way 1

In VueJS-

new Vue({
  el: 'body',
  data:{
    lists : '<img src="https://s-media-cache-ak0.pinimg.com/564x/92/e0/72/92e0720cb077619578eb14394d1dbee7.jpg"/>';
  },

Now you need to print this in html template. In your html template-

{{{ lists }}}

Continue reading "How to print html code in VueJS"

How to print html code in VueJS

How to find country using IP address in PHP?

If you have visitor IP address and you want to find out the country of this visitor, may be you can try this.

function getCountryName($ip_addr){
    $return_data  = array('country'=>'', 'city'=>'');
    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip_addr));
    if($ip_data && $ip_data->geoplugin_countryName != null)
    {
        $return_data['country'] = $ip_data->geoplugin_countryCode;
        $return_data['city'] = $ip_data->geoplugin_city;
    }
    return $return_data;
}   

Now call this function where you want to call this.

echo getCountryName('192.168.0.1');

Thank you.

How to find country using IP address in PHP?

Difference between array_merge and array + array in PHP

Sometimes, I wondered that, what is the different between array_merge and array + array. Both of them are working in a same way. If so, what is the purpose of using both?

Well, let’s see..

array_merge

array_merge() concat more than one array together and retuans its result as an array.

For example-

$a = array('foo' => 'bar');
$b = array('foo' => ''); // or false or 0
print_r(array_merge($a, $b));

Here, the result is-

Array
(
    [foo] => 0
)

It takes the union BUT the duplicate keys are overwritten

Continue reading "Difference between array_merge and array + array in PHP"

Difference between array_merge and array + array in PHP

Laravel add video with Laravel Videoable

Nwidart wrote a nice package for laravel where you can easily add video in your system. In this tutorial, I will use Laravel videoable pacakge.

Install

Install Via Composer
Just execute follow command to download the package.

composer require nwidart/laravel-videoable

Next add the following service provider in config/app.php.

'providers' => [
  Nwidart\LaravelVideoable\LaravelVideoableServiceProvider::class,
],

Continue reading "Laravel add video with Laravel Videoable"

Laravel add video with Laravel Videoable

Class App\Repositories does not exist in Laravel

Are you faceing Class App\Repositories... does not exist in Laravel suddenly? If so, this post might help you to solve this issue.

Go to composer.json and add following line there-

 "autoload": {
        "classmap": [
            "database",
            "app/Repositories"            
        ],

Now, the final things that you need to do, open command line and execute-

composer dump-autoload

Now try, hope will work perfectly.

Class App\Repositories does not exist in Laravel

How to make human readable Time in VueJS

Are you big fan of PHP Carbon library? Do you want to make your VueJS time stamp like Carbon formate? For example, a time stamp that show human readable by showing how many minutes / hours ago.

In this case, you can do it simply wrting a drective in your vueJS. Lets do that.

Here, we need to use a Javascript library called Moment JS. You can use CDN like that-

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.js"></script>

In you vue, just write a directive like so-

directives : {
    dateshow : function (value){
        var date=moment(value).fromNow(); // here u modify data. Just follow the format there... https://momentjs.com/
        this.el.innerText=date; // and set to the view

    }
}

Now, in your view page, write this code, where you need to show the date time.

<li v-dateshow='user.created_at'> </li> // Here, user.created_at comes from database and display via VueJS.

Hope, it will work. Thank you.

How to make human readable Time in VueJS