For example you’re developing an app in Laravel. You want to add a new Route to routes/web.php
file.
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 use
statement 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…
0 yorum