Best code snippets, tutorials and more

Coursecomp is your starting point for developing and maintaining your web application.

How to add hash (#) to a route redirect in Laravel

If you want to use redirect to a specific section on a page, you might want to use withFragment(), so you can use the fragment of the URI: You can also utilize this method when redirecting upon form completion: Via @ecrmnn

How to make code shorter with QueryBuilder in Laravel

Imagine, we need to get the name of the first admin in our web application. We can do that in two ways: The first way, using four lines of code, and if the user is not present, it will throw an error: The second way uses only 2 lines of code, and if the user […]

How to use URL Facade in Laravel

Laravel quick tip! URL Facade is a cool feature in Laravel that allows you to extract the current, previous, and full URLs on any given web page. See the example below: https://coursecomp.com/user/admin/ https://coursecomp.com/user/admin/?foo=bar https://coursecomp.com/news/

How to check if PIP is installed or not on Mac OS

Python is a programming language with many features that make it well suited for scripting, automation, and data analysis. The latest version of python for Mac OS is 3.6.3. This version includes bug fixes and improvements to existing features, with the most notable change of adding an enclosure keyword and support for type annotation. You […]

How to use count() within a loop in PHP? Put it outside

In order to make your code cleaner, the best way is to use the count() function outside of the loop. See the example below: What it count() in PHP? The count() function is a built-in function in PHP that we use to count the number of elements in an array. We can also use it […]

How to update timestamp column in Laravel

If you want to update a timestamp column in a specific model, you can use touch method, instead of using update. This functionality has been added Since Laravel 9.25 it is now also possible to use the touch method on the query builder as well (was only possible on a model previously). But remember, touch […]

How to display 0 but not empty string values or null in Laravel

There is a beautiful filled() method in Laravel so that you can avoid unnecessary outputs in your rendering blade-templates. Here is the example: Quantity per serving Energy 1438 kJ / 338 kcal Protein 0 Fat 0 Carbohydrate 85 See the official documentation. Thnx to Daniel Eckermann.

How to use isset() with multiple variables

There is a smart way of using the isset() function in PHP when dealing with several variables. The old-fashioned way: The easiest and smart way to use isset() with multiple variables:

How to Disable Pingbacks in WordPress

Pingback is a WordPress feature that automatically notifies other WordPress blogs that you have linked to them. This is done by sending a pingback XML-RPC request to the other blog’s pingback URL. If the other blog accepts pingbacks, it will display a link to your post. Pingbacks can help build backlinks, raise your domain authority […]