Keyword research

The number one place for your keyword research is Google Ads Keyword planner.

This tool will give you suggestions, amount of search for each suggestion during a given time frame as well as competition on the keyword regarding advertisement. A lot of useful information.

If your site is up and running, you will find another useful source of keyword to explore in google webmaster tools.

Other sources of keyword are ahref and semrush

Add the url parameters for Laravel search results pagination

Issue: If you paginate your search result, when clicking on the 2 page, or any other nth page of your pagination link, it will return an url with the page parameter but without your search parameter. This cause your filtering to be lost.

Solution:

Make sure to return your parameter variable from the controller function as you will need to call it on your blade view.

return view('my_view',compact( 'queryResult','my_variable'));

In your view:

@foreach($queryResult   as $stuff)
     {{$stuff->stuff_name}}
 @endforeach
{{$ queryResult ->appends(['search_variable=>$my_variable])->links('vendor.pagination.materializecss')}}

if you have several URL parameters you can align the ->appends() one after the other. Don’t forget to ad the varaible to the view in the controller.

Passing variables to Laravel parameter grouping function

Issue: A statement such as

$nb_votes = $request->input('nb_votes');
DB::table('users')
            ->where('name', '=', 'John')
            ->where(function ($query) {
                $query->where('votes', '>', $nb_votes)
                      ->orWhere('title', '=', 'Admin');
            })
            ->get();

will return an error:

Unknown variable $nb_votes 

The issue is due to the fact that $nb_votes in the anonymous function refers to the local scope, while the variable we want to use has been defined outisde of the function. We need to pass the variable to the anonymous function.

Solution: To pass a variable to an anonymous function you can do as follow:

$nb_votes = $request->input('nb_votes');
DB::table('users')
            ->where('name', '=', 'John')
            ->where(function ($query) use ( $nb_votes ) {
                $query->where('votes', '>', $nb_votes)
                      ->orWhere('title', '=', 'Admin');
            })
            ->get();

https://www.php.net/manual/en/functions.anonymous.php

see last example in example #3

For laravel queries documentation:

https://laravel.com/docs/5.8/queries#parameter-grouping

Check if a function is declared before using it in js

Issue: it may occurs that you have to call a function that is conditionally set. A frequent use case would be GDPR where you set your tracking script conditionally. You micht check the cookie for each event you track, but I think a better solution would be to track if the function is declared.

Solution:

There are two different options:

Option 1:

This option will still return an error in case the function to evaluate is not defined.

function isFunction(TrackingScript) {
   TrackingScript ('button-click','cart',10);
}

Option 2:

if (typeof( TrackingScript ) === typeof(Function)){
       TrackingScript ('button-click','cart',10); 
}

Control which modules are shown in the search result pages in joomla and virtuemart

Issue: When doing a search on the home page of a joomla/vituemart website, the layout used for the result pages will be the one of the home page. This might not be desirable if you are using modules to display home page specific content.

Solution: we will add a condition to control the display of specific module position in your template index.php

Step 1 get the URL

$url = filter_var (  $_SERVER['REQUEST_URI'],FILTER_SANITIZE_URL);

Step 2 check if a certain string is in the URL (‘keyword’ is a good candidate to filter out search result pages).

strpos($url ,'keyword')

Step 3 add a condition to control the display the module depending on the result of the check above.

if ($mobilehide && $this->params->get('top-b')  || strpos($url ,'keyword') !== FALSE){
//Do nothing
}
else{
//Display the module
}