Best code snippets, tutorials and more

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

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 […]

How to send email with uploaded files attached In Laravel

Laravel tip: if you want to send emails having user uploaded files attached, you don’t need to save the file first. Instead, you just attach the uploaded file with attachData method and that’s it! Here is the example from a Mailable class: Via @ecrmnn.

How to use whereColumn() method in Laravel

Quick tip: you can use a pretty handy Eloquent method called whereColumn() to verify if columns are equal. For example, you can find posts that have been updated or posts which have the same title and slug. Here is the code: Read more in the official documentation here.

How to reduce code duplication with relationships in Laravel

Since Laravel 9.16 we can reduce the code a bit, using withWhereHas() method. It’s time to do some code clean up! See the example below: As Laravel contributor Eusonlito describes: There are a lot of times that we need to load a relationship using with with the same conditions that we use for whereHas. This method simplifies this […]

How to Add Values to the Form Request After Validation in Laravel

Sometimes it’s necessary to add more values to the form request after it has been validated. These values get returned in this method even though they were not part of the request. For this, we can use the method validated() in our form request and merge the original request data with our custom data. In […]

How to filter by NULL in Eloquent Collections Laravel

Eloquent collections are one of the most powerful tools in the Laravel toolbox. They give you a fluent, convenient wrapper for complex SQL queries. You can chain together different conditions to create complex queries and then call methods on the resulting collection to fetch your data. And here comes the trap. For example, you filter […]

How to use Laravel dd() method with less code

Hello, guys! Did you know that you don’t have to wrap your Eloquent query with dd() method, and just simple can add it at the end of the query? See how simple it is. How to use dd() in Laravel What is dd() in Laravel? Dump and Die, or dd(), is a Laravel helper function […]

How to add custom CSS rules in Tailwind CSS Typography plugin

Sometimes, it is necessary to add some styling to your Tailwindcss .prose class. You can do that in two ways. The first one is obvious: you add some additional CSS classes. Imagine you need to change your headings and paragraphs text to black color. Then, you suddenly realize that also you have to change your […]