Custom Helpers

Several possibilities: https://stackoverflow.com/questions/57560226/how-to-use-class-from-blade-template Sometimes, it's necessary to have custom PHP code used in Laravel blade files. https://localhost/tools/ObsidianBook/index.php

Using custom facade

(for short simple helpers NOT recommended)

Using alias in config/app

Helper code created by developer is best located in classes using namespace App\Helpers or App\Services.

Custom Helper class is included in config/app.php Class Aliases, e.g. 'Helper' => App\Helpers\Helper::class,

PhpStorm - Code completion of aliased custom helper in blade code

Unfortunately, using custom classes without full namespace in blade file PhpStorm provides no code auto-completion.

Top best possible solution

  1. When inserting Helper code in blade at first, use full namespace for easy auto-completion.
  2. When finished with its testing, then namespace prefix can be removed. Because it is aliased in config.app it should work without prefix.
  3. With short class alias is standard auto-completion no more available. But putting cursor on helper class method together with keyboard stroke 'CTRL+SHIFT+i' opens modal window with helper method code.
    This is an image
  4. For better information about method code, use PHPDoc comment.

Second-best possible solution

Custom class signature can be included into file _ide_helper.php generated by barryvdh/laravel-ide-helper (command php artisan ide-helper:generate) when:

  1. Custom class is included in config/app.php Class Aliases, e.g., 'Helper' => App\Helpers\Helper::class,

  2. Custom class has PHPDoc for the class (located above class code) containing signatures for class methods (PHPDoc above method code is NOT included in generated file _ide_helper.php) e.g.

	/**
	 * Class description
	 *
	 * @method static string stripTags_(string)
	 * @method static string properUrl_(string $str)
	....
	 */

Important! The method name has appended _ for preventing PhpStrom to indicate duplicate method names. If this PhpStrom warning (which is not possible to suppress - PhpStrom issue) is not disturbing you can leave original method names.

Example of code completion in Laravel blade file

This is an image