CODE Formating

PHP Formatting

In Vs Code, install Laravel Pint and Laravel Blade Formatter

Laravel Pint and Laravel Blade Formatter support for Vs code with PHP 8.x

Installation

Requirements

  • You must have a running copy of PHP on the machine you are running Vs Code

Install these extensions through Vs Code extension

  • In Vs Code press ctrl+shift+x
  • Search for extention
  • Choose the extension
  • Install the extension

Configuration (Windows)

Laravel Print
  • To enable formatting on save in your editor, use configurations like this

pint1

  • With this configuration in place, when you save a PHP file, it will be automatically formatted according to the Laravel Pint preset that you specified in the pint.json file.

  • Create a pint.json file in the root directory.

pintJson

  • Take a look at the pint.json file to have an idea how you define rules.

pint2

Laravel Blade Formatter
  • With the Blade template file open, you can format it by using the shortcut Shift + Alt + F on Windows/Linux or Shift + Option + F on macOS. Alternatively, you can right-click inside the file and select "Format Document".

blade

Settings

Laravel Print

You can set Laravel Pint as the default formatter for your PHP files in VS Code. Open the VS Code settings (either user or workspace preferences) and add the following configuration.

{
  "[php]":
{
    "editor.defaultFormatter": "open-southeners.laravel-pint",
  }
}
Laravel Blade Formatter
  • You can create bladeformatterrc.json or .bladeformatterrc in your project root.

bladeSetting

{
    "endWithNewLine": true,
    "indentSize": 4,
    "noMultipleEmptyLines": true,
    "noPhpSyntaxCheck": false,
    "noSingleQuote": false,
    "sortHtmlAttributes": "none",
    "sortTailwindcssClasses": true,
    "useTabs": false,
    "wrapAttributes": "auto",
    "wrapAttributesMinAttrs": 3,
    "wrapLineLength": 200
}

results matching ""

    No results matching ""

    results matching ""

      No results matching ""