0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【PHP】use宣言のグループ化

Posted at

Before

<?php

namespace App\Http\Controllers;

use App\Models\Hoge;
use App\Models\Fuga;
use App\Models\Foo;
use App\Models\Bar;
use App\Futaba\Chimaki as Chima;
use App\Futaba\Ribon as Bon;
use App\Futaba\Sakura as Saku;

class HogeController extends Controller
{
	//
}

After (PHP 7 以降のコード)

<?php

namespace App\Http\Controllers;

use App\Models\{
  Hoge, Fuga, Foo, Bar
};
use App\Futaba\{
  Chimaki as Chima,
  Ribon as Bon,
  Sakura, as Saku
};

class HogeController extends Controller
{
	//
}
  • Tinkerでも有効
  • as(エイリアス)も指定できる

途中まで同じパスが多い場合は、まとめてあげると見やすいですね!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?