Category Archives: Frameworks

Laravel testing – disable throttling

Use this code at your base class:

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Routing\Middleware\ThrottleRequests;

abstract class TestCase extends BaseTestCase
{
use CreatesApplication;

protected function setUp(): void
{
parent::setUp();

$this->withoutMiddleware(
ThrottleRequests::class
);
}
}

Vue JS – htaccess file for history mode

Here is a working example:

<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

Or another solution: (tested in siteground)

RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://myURL.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.html [L]

Laravel-VSCODE X-debug configuration

Table of contents

  1. Install x-debug
  2. Configure x-debug
  3. Run the x-debug listener in VS-Code
  4. Configure the task to launch laravel
  5. Debug the project

In this article we assume that php is already installed.

Install x-debug

sudo apt-get install php-xdebug

Configure x-debug

Run phpinfo() to find which php.ini you need to edit:

php -i | grep "Loaded Configuration File"

For example the path might be:

/etc/php/8.3/cli/php.ini

You need to edit the php.ini file to configure (x-debug 3). You may change the values according to your needs. The default port of x-debug is 9000 but it is highly recommended to change it because more often that not that port is used by another application.

[xdebug]
xdebug.mode=debug
xdebug.client_port=11887
xdebug.client_host=0.0.0.0
xdebug.remote_handler=dbgp
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.idekey=VSCODE
xdebug.show_error_trace = 1
xdebug.max_nesting_level=250
xdebug.var_display_max_depth=10
xdebug.log=/tmp/xdebug.log

Run the x-debug listener in VS-Code

In VS Code, install the plugin for x-debug

Then add in the launch.json:

{
"version": "0.2.0",
"configurations": [
{
"name": "Listen with Xdebug",
"type": "php",
"request": "launch",
"port": 11887
}
]
}

You can run press F5 to start the listener. Once you do, you may launch the Laravel project however you want and it should stop at the break points.

It is recommended to run the listener BEFORE the Laravel application.

Configure the task to launch laravel

Create the task to launch Laravel.

For example:

{
"version": "2.0.0",
"tasks": [
{
"label": "php artisan serve",
"type": "shell",
"command": "php artisan serve",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [],
"isBackground": true
},
{
"label": "php artisan test",
"type": "shell",
"command": "php artisan test",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "shared"
}
}
]
}

Debug the project

In order to debug the project, You need to do the following steps:

  • Press F5 to launch the x-debug listener
  • Press CTRL+SHIFT+P to run the task that runs Laravel (php artisan serve)

Laravel Logo with your text

Simple SVG example to replace the label on the home page.

Set the APP_NAME in your env file or in the config as usual.

<svg viewBox="0 0 900 192" fill="none" xmlns="http://www.w3.org/2000/svg" class="h-16 w-auto text-gray-700 sm:h-20">
<g clip-path="url(#clip0)" fill="#EF3B2D">
<path d="M184.068 43.892c-.024-.088-.073-.165-.104-.25-.058-.157-.108-.316-.191-.46-.056-.097-.137-.176-.203-.265-.087-.117-.161-.242-.265-.345-.085-.086-.194-.148-.29-.223-.109-.085-.206-.182-.327-.252l-.002-.001-.002-.002-35.648-20.524a2.971 2.971 0 00-2.964 0l-35.647 20.522-.002.002-.002.001c-.121.07-.219.167-.327.252-.096.075-.205.138-.29.223-.103.103-.178.228-.265.345-.066.089-.147.169-.203.265-.083.144-.133.304-.191.46-.031.085-.08.162-.104.25-.067.249-.103.51-.103.776v38.979l-29.706 17.103V24.493a3 3 0 00-.103-.776c-.024-.088-.073-.165-.104-.25-.058-.157-.108-.316-.191-.46-.056-.097-.137-.176-.203-.265-.087-.117-.161-.242-.265-.345-.085-.086-.194-.148-.29-.223-.109-.085-.206-.182-.327-.252l-.002-.001-.002-.002L40.098 1.396a2.971 2.971 0 00-2.964 0L1.487 21.919l-.002.002-.002.001c-.121.07-.219.167-.327.252-.096.075-.205.138-.29.223-.103.103-.178.228-.265.345-.066.089-.147.169-.203.265-.083.144-.133.304-.191.46-.031.085-.08.162-.104.25-.067.249-.103.51-.103.776v122.09c0 1.063.568 2.044 1.489 2.575l71.293 41.045c.156.089.324.143.49.202.078.028.15.074.23.095a2.98 2.98 0 001.524 0c.069-.018.132-.059.2-.083.176-.061.354-.119.519-.214l71.293-41.045a2.971 2.971 0 001.489-2.575v-38.979l34.158-19.666a2.971 2.971 0 001.489-2.575V44.666a3.075 3.075 0 00-.106-.774zM74.255 143.167l-29.648-16.779 31.136-17.926.001-.001 34.164-19.669 29.674 17.084-21.772 12.428-43.555 24.863zm68.329-76.259v33.841l-12.475-7.182-17.231-9.92V49.806l12.475 7.182 17.231 9.92zm2.97-39.335l29.693 17.095-29.693 17.095-29.693-17.095 29.693-17.095zM54.06 114.089l-12.475 7.182V46.733l17.231-9.92 12.475-7.182v74.537l-17.231 9.921zM38.614 7.398l29.693 17.095-29.693 17.095L8.921 24.493 38.614 7.398zM5.938 29.632l12.475 7.182 17.231 9.92v79.676l.001.005-.001.006c0 .114.032.221.045.333.017.146.021.294.059.434l.002.007c.032.117.094.222.14.334.051.124.088.255.156.371a.036.036 0 00.004.009c.061.105.149.191.222.288.081.105.149.22.244.314l.008.01c.084.083.19.142.284.215.106.083.202.178.32.247l.013.005.011.008 34.139 19.321v34.175L5.939 144.867V29.632h-.001zm136.646 115.235l-65.352 37.625V148.31l48.399-27.628 16.953-9.677v33.862zm35.646-61.22l-29.706 17.102V66.908l17.231-9.92 12.475-7.182v33.841z"/>
</g>
<text x="210" y="130" fill="red" font-size="6em" letter-spacing="-2" font-weight="bold">{{ config('app.name') }}</text>
</svg>

Laravel – Makefile Recipes

Table for contents

  1. Generator
  2. Getting information
    1. Laravel and composer
    2. Endpoints
    3. Log file
  3. Running developer tools
    1. Tinker
  4. Testing
    1. Testing
  5. Clean up
    1. Clear cache
    2. Clear storage
    3. Clear log file (default configuration)

Generator

You can generate recipes at Nicomedes.

Getting information

Laravel and composer
.PHONY: info
info:
php artisan about
php composer.phar diagnose
Endpoints
.PHONY: routes
routes:
php artisan route:list
Log file
.PHONY: logs
logs:
grep ERROR storage/logs/laravel.log

Running developer tools

Tinker
.PHONY: tinker
tinker:
php composer.phar dump-autoload
php artisan tinker

Testing

Testing
.PHONY: test
test:
php artisan test --env=testing --stop-on-failure

Clean up

Clear cache
php composer.phar dump-autoload
php artisan optimize:clear
Clear storage
.PHONY: clear\:storage
clear\:storage:
rm -rf ./storage/app/*
Clear log file (default configuration)
.PHONY: clear\:log
clear\:log:
rm storage/logs/laravel.log

Laravel links 🏅

  1. Useful online tools (free only)
  2. Laravel modules (free only)
  3. Laravel Articles
    1. Laravel – Basics
    2. Profiling and optimization
    3. Advanced
    4. Laravel – Eloquent
    5. Laravel – Architecture
    6. Laravel – Response
    7. Laravel – REST
    8. Laravel – GUI:
    9. Laravel – validation
    10. Laravel – Authentication and authorization:
    11. Laravel – CRUD
    12. Laravel – Migrations
    13. Laravel – Mass assignment
    14. Laravel – How to create PDFs
    15. Laravel – Digitally sign PDFs:
    16. Laravel – Repository pattern discussions
    17. Laravel – logging
    18. Laravel – Troubleshooting
    19. Laravel – deployment
    20. Laravel – Tinker
    21. Inertia JS
  4. Laravel Theory
    1. Best practices
    2. Facades and statics

Useful online tools (free only)

Laravel modules (free only)

LibraryUsage
ClockworkProfiling
EnlightenDocumentation generation from test units
HorizonQueue manager
MonologAdvanced logging
Spatie Query builderAdvanced query builder
Spatie DB dumberEasy export database in .sql files

Laravel Articles

Laravel – Basics

Profiling and optimization

Advanced

Laravel – Eloquent

Laravel – Architecture

Laravel – Response

Laravel – REST

Laravel – GUI:

Laravel – validation

Laravel – Authentication and authorization:

Laravel – CRUD

Laravel – Migrations

Laravel – Mass assignment

Laravel – How to create PDFs

Laravel – Digitally sign PDFs:

Laravel – Repository pattern discussions

Laravel – logging

Laravel – Troubleshooting

Laravel – deployment

Laravel – Tinker

Inertia JS

Laravel Theory

Best practices

Facades and statics

Spring boot – CORS configuration

Table of contents:

  1. Without security:
  2. With security:

Without security:

In the application class, add the following code:

@Bean
public WebMvcConfigurer corsConfigurer() {
  return new WebMvcConfigurer() {
  @Override
  public void addCorsMappings(CorsRegistry registry)  {				registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD").allowedHeaders("*");
  }
  };
}

With security: