Best code snippets, tutorials and more

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

How to make Codepen-like button with animated gradient border

In previous post, we showed how to make gradient border with CSS. This time, we go a little bit further. Let’s take a look at the beautiful button “Start coding” on homepage (you have to be logged out to see it). It also animates beautifully on mouse over: Here you are, beautiful button: See […]

How to use gradients for borders in CSS

The border-image-source property allows you to set a trendy gradient for the element’s border. Try it on Codepen. Remember, this code does not work with the border-radius property because it is not supported with border-image. If you want to have rounded borders, you can try this code: See Codepen

How to use whereRelation method in Laravel

Laravel tip. You can use the whereRelation method (introduced in Laravel 8.57+) instead of whereHas when filtering by a simple where statement. The only downside is that you cannot use scopes, whereRelation is suitable for only one simple “where” statement. The merit of using whereRelation is shorter and more readable syntax, and in terms of […]

How to render SVG with Blade components in Laravel

Laravel is a very flexible framework, and you can reutilize your Blade components when it comes to SVG rendering. You can use {{ $.attributes }} in the component itself to pass custom attributes like (e.g., “class”). Just look at the following syntax: File structure: Helpful tip If you see the use of href="#!" and have […]

How to use conditions in Laravel Eloquent

Eloquent is a brilliant ORM – you can use conditions in relationships. In this example, we have multiple users. In the next step, we set a relationship called admins which extends the user relation with a condition. So easy! But you have to be mindful when creating a user via admins relationship. You will need […]

How to push jobs to the queue in Laravel (Cheat sheet)

Here is the cheat sheet on the ways you can push jobs to queue in your Laravel application: If you are configuring Laravel Queues with AWS SQS, and you want to queue a job later than 15 minutes in the future, you may want to use the Laravel Haystack package. You can also use the Bus::chain method […]

How to check if a string is valid JSON in Laravel

It is very common when you have to check whether a string is a valid JSON or not. An example of Str::isJson in Laravel In Laravel, you may want to use Str::isJson method as follows: These are examples from the official documentation: What is JSON for? JSON is a data format that helps exchange data […]

How to use constructor promotion in PHP 8

This is so good! The only thing that feels wrong is the empty brackets. What is a constructor property promotion? It is a new syntax that PHP 8 brings, allowing two simultaneous operations: Class property declaration and Constructor assignment, right from the constructor. See how it works: See the official documentation.