For example you’re developing an app in Laravel. You want to add a new Route to routes/web.phpfile.

Route::get('payment', 'App\\Http\\Controllers\[email protected]');

As you can see you must write class and method name as string. But you can make this better way:

Route::get('payment', [App\Http\Controller\PaymentController::class, 'pay']);

This is better then other becouse you can open the controller with CMD+LeftClick to class name. But class namespace is too long. You can set PHPStorm for automatically add usestatement at top of file. For this you must check that option:

Preferences/Editor/General/Auto Import/Enable auto-import in file scope

After that PHPStorm will make it like that:

use App\Http\Controllers\PayOrderController;
use Illuminate\Support\Facades\Route;

Route::get('pay', PayOrderController::class);

As you can see this method is more clear and readable. Happy coding…

Kategoriler: PHP

0 yorum

Bir cevap yazın

Avatar placeholder

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

This site uses Akismet to reduce spam. Learn how your comment data is processed.