{"id":8333,"date":"2020-11-23T07:00:55","date_gmt":"2020-11-22T22:00:55","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=8333"},"modified":"2020-11-20T03:19:11","modified_gmt":"2020-11-19T18:19:11","slug":"php-8-%e3%81%ae%e6%96%b0%e6%a9%9f%e8%83%bd%e3%82%92laravel%e3%81%a7%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=8333","title":{"rendered":"PHP 8 \u306e\u65b0\u6a5f\u80fd\u3092Laravel\u3067\u4f7f\u3063\u3066\u307f\u305f"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u7686\u3055\u3093\u3082\u3088\u304f\u3054\u5b58\u77e5\u306e\u3068\u304a\u308a\u3067\u3059\u304c\u3001<code>Larave<\/code>\u3060\u3051\u3067\u306a\u304f<code>PHP<\/code>\u81ea\u4f53\u3082\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3092\u7e70\u308a\u8fd4\u3057\u3066\u3044\u3066\u3001\u5e38\u306b\u65b0\u3057\u3044\u6a5f\u80fd\u304c\u52a0\u308f\u3063\u305f\u308a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u6765\u305f\u308b\u300c<strong>2020.11.26<\/strong>\u300d\u306b\u6b21\u671f\u30d0\u30fc\u30b8\u30e7\u30f3\u306e<code>PHP 8<\/code>\u304c\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u3063\u3066\u307e\u3059\uff08\u79c1\u304cPHP\u3092\u4f7f\u3044\u59cb\u3081\u305f\u306e\u304c\u30d0\u30fc\u30b8\u30e7\u30f34\u3067\u3057\u305f\u306e\u3067\u3001\u4f55\u304b\u8aac\u660e\u306e\u3067\u304d\u306a\u3044\u8208\u596e\u304c\u3042\u308a\u307e\u3059\ud83d\ude02\uff09<\/p>\n<p><code>PHP 8<\/code>\u306e\u76ee\u7389\u6a5f\u80fd\u3068\u3057\u3066\u306f\u3001\u3084\u306f\u308a\u300c<strong>JIT\u30b3\u30f3\u30d1\u30a4\u30e9<\/strong>\u300d\u306b\u3088\u308b\u8d85\u9ad8\u901f\u5316\u3067\u3059\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7684\u306b\u3082\u3044\u304f\u3064\u304b\u300c<strong>\u304a\u3063\uff01<\/strong>\u300d\u3068\u601d\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u3001\u305d\u306e\u6c17\u306b\u306a\u308b<code>PHP 8<\/code>\u306e\u65b0\u6a5f\u80fd\u3092<code>Laravel<\/code>\u3067\u4f7f\u3063\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6068 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/>\u300c\u30d7\u30ec\u30b9\u30c6\u3082\u3001\u3082\u3046<code>5<\/code>\u306b\u306a\u308b\u3093\u3067\u3059\u306d\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 8.x<\/p>\n<h1 id=\"named-arguments-rfc\">\u95a2\u6570\u306b\u6e21\u3059\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u9806\u756a\u304c\u81ea\u7531\u306b\u306a\u308b<\/h1>\n<p>\u3053\u308c\u307e\u3067\u306e<code>PHP<\/code>\u3067\u306f\u3001\u95a2\u6570\u306b\u6e21\u3059\u5f15\u6570\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\uff09\u306f\u5fc5\u305a\u9806\u756a\u3092\u5b88\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001<code>Laravel<\/code>\u306e\u30d8\u30eb\u30d1\u30fc\u95a2\u6570<code>Str::padLeft()<\/code>\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n<span style=\"font-size: 1rem;\">\u307e\u305a\u306f\u3001\u5b9a\u7fa9\u306f\u3053\u3046\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<pre>\/\/ Laravel \u304b\u3089\u5f15\u7528\r\n\r\npublic static function padLeft(<strong>$value, $length, $pad = ' '<\/strong>)\r\n{\r\n    return str_pad($value, $length, $pad, STR_PAD_LEFT);\r\n}<\/pre>\n<p>\u3053\u306e\u5f15\u6570\u306e\u9806\u756a\u306b\u6ce8\u76ee\u3057\u3066\u307f\u308b\u3068\u3001\u3082\u3057\u95a2\u6570\u3092\u4f7f\u3044\u305f\u3044\u5834\u5408\u306f\u3001<\/p>\n<ol>\n<li>$value<\/li>\n<li>$lenth<\/li>\n<li>$pad<\/li>\n<\/ol>\n<p>\u306e\u9806\u756a\u3067\u30bb\u30c3\u30c8\u3057\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u3053\u3093\u306a\u30ab\u30f3\u30b8\u3067\u3059\u3002<\/p>\n<pre><strong>$value = '123';<\/strong>\r\n<strong>$length = 10;<\/strong>\r\n<strong>$pad = '0';<\/strong>\r\n\r\n\/\/ \ud83d\udc47 \u5f15\u6570\u306e\u9806\u756a\u306f\u6c7a\u307e\u3063\u3066\u307e\u3059\r\n$text = Str::padLeft(<strong>$value, $length, $pad<\/strong>);<\/pre>\n<p>\u3057\u304b\u3057\u3001<code>PHP 8<\/code>\u304b\u3089\u306f\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>$text = Str::padLeft(\r\n<strong>    value: '123',<\/strong>\r\n<strong>    length: 10,<\/strong>\r\n<strong>    pad: '0'<\/strong>\r\n);<\/pre>\n<p>\u305d\u306e\u305f\u3081\u3001\u9806\u756a\u306f\u95a2\u4fc2\u306a\u304f\u306a\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3082\u540c\u3058\u7d50\u679c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>$text = Str::padLeft(\r\n    <strong>pad: '0', \/\/ \ud83d\udc48 \u9806\u756a\u306f\u6c17\u306b\u3057\u306a\u304f\u3066OK<\/strong>\r\n<strong>    length: 10, \/\/ \ud83d\udc48 \u3053\u3053\u3082<\/strong>\r\n<strong>    value: '123' \/\/ \ud83d\udc48 \u3053\u3053\u3082<\/strong>\r\n);<\/pre>\n<p>\u307e\u3060\u5b9f\u969b\u306e\u958b\u767a\u3067\u4f7f\u3063\u3066\u3044\u306a\u3044\u3067\u3059\u304c\u3001\u53ef\u8aad\u6027\u306f\u4e0a\u304c\u308b\u3068\u601d\u3044\u307e\u3059\u3057\u3001<code>IDE<\/code>\u304c\u81ea\u52d5\u7684\u306b\u3053\u306e\u5f62\u5f0f\u3067\u81ea\u52d5\u5165\u529b\u3057\u3066\u304f\u308c\u308b\u306a\u3089\u3001\u3053\u3063\u3061\u306e\u66f8\u304d\u65b9\u3082\u30a2\u30ea\u304b\u306a\u3068\u601d\u3063\u3066\u307e\u3059\ud83d\udc4d\uff08\u305f\u3060\u3057\u3001\u5f15\u6570\u304c\u5c11\u306a\u3044\u5834\u5408\u306f\u306a\u3057\u306e\u65b9\u304c\u3044\u3044\u3067\u3059\u306d\uff09<\/p>\n<h1 id=\"match-expression-rfc\">switch()\u304c\u9032\u5316\u3057\u305f\u3088\u3046\u306amatch()\u95a2\u6570<\/h1>\n<p><code>PHP 8<\/code>\u306b\u306f\u65b0\u3057\u3044\u6761\u4ef6\u5206\u5c90<code>match()<\/code>\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092<code>Laravel<\/code>\u306e\u30e2\u30c7\u30eb\u3067\u4f7f\u3063\u3066\u307f\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306f\u3001\u5546\u54c1\u306e\u5024\u6bb5\u3067\u5206\u5c90\u3092\u3059\u308b\u4f8b\u3067\u3059\u3002<\/p>\n<pre>$item = Item::find(1);\r\n\r\n$text = <strong>match($item-&gt;price) {<\/strong>\r\n<strong>    500 =&gt; '\u30ef\u30f3\u30b3\u30a4\u30f3\u3067\u3059',<\/strong>\r\n<strong>    1000, 2000, 3000 =&gt; '\u5207\u308a\u306e\u3044\u3044\u5024\u6bb5\u3067\u3059',<\/strong>\r\n<strong>    default =&gt; '\u597d\u8a55\u767a\u58f2\u4e2d'<\/strong>\r\n<strong>};<\/strong><\/pre>\n<p><code>$text<\/code>\u306e\u4e2d\u8eab\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5024\u6bb5\u304c 500 \u306e\u5834\u5408\uff1a \u300c\u30ef\u30f3\u30b3\u30a4\u30f3\u3067\u3059\u300d<\/li>\n<li>\u5024\u6bb5\u304c 1000, 2000, 3000 \u306e\u5834\u5408\uff1a \u300c\u5207\u308a\u306e\u3044\u3044\u5024\u6bb5\u3067\u3059\u300d<\/li>\n<li>\u305d\u308c\u4ee5\u5916\uff1a \u300c\u597d\u8a55\u767a\u58f2\u4e2d\u300d<\/li>\n<\/ul>\n<h1 id=\"the-nullsafe-operator-rfc\">\u30c1\u30a7\u30fc\u30f3\u30e1\u30bd\u30c3\u30c9\u3067Null\u306a\u3089\u9014\u4e2d\u3067\u7d42\u4e86\u3059\u308b\u6a5f\u80fd<\/h1>\n<p>\u30c1\u30a7\u30fc\u30f3\u30e1\u30bd\u30c3\u30c9\u3068\u3044\u3046\u306e\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>-&gt;<\/code>\u3067\u3064\u306a\u3044\u3060\u30b3\u30fc\u30c9\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<pre>$users = User::get();\r\n$user_names = $users<strong>-&gt;<\/strong>filter(function($user) {\r\n\r\n    return $user-&gt;id &gt; 3;\r\n\r\n})\r\n<strong>-&gt;<\/strong>pluck('name')\r\n<strong>-&gt;<\/strong>map(function($user_name) {\r\n\r\n    return $user_name .'\u69d8';\r\n\r\n});<\/pre>\n<p>\u3053\u306e\u66f8\u304d\u65b9\u306f\u30b3\u30fc\u30c9\u304c\u3059\u3063\u304d\u308a\u3059\u308b\u306e\u3067\u3068\u3066\u3082\u4fbf\u5229\u3067\u3059\u304c\u3001\u4e00\u70b9\u300c\u3046\u30fc\u3093\u300d\u306a\u70b9\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u304c\u3001\u300c<strong>\u9014\u4e2d\u3067<code>null<\/code>\u304c\u8fd4\u3063\u3066\u304d\u3066\u3082\u5b9f\u884c\u304c\u6b62\u307e\u3089\u305a\u3001\u7d50\u679c\u30a8\u30e9\u30fc\u304c\u51fa\u308b<\/strong>\u300d\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u304c\u3001<code>PHP 8<\/code>\u3067\u306f\u3001<code>?-&gt;<\/code>\u3092\u4f7f\u3046\u3053\u3068\u3067\u51e6\u7406\u304c\u9014\u4e2d\u3067\u6b62\u307e\u308b\uff08\u305d\u308c\u4ee5\u964d\u306e\u30b3\u30fc\u30c9\u306f\u3061\u3083\u3093\u3068\u5b9f\u884c\u3055\u308c\u307e\u3059\uff09\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>public function index(Request $request)\r\n{\r\n    $user_name = <strong>$request-&gt;user()?-&gt;name;<\/strong>\r\n}<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001<code>user()<\/code>\u304c<code>NULL<\/code>\u306e\u5834\u5408\u3001\u305d\u308c\u4ee5\u964d\u306f\u7121\u8996\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3082\u3057\u3053\u308c\u307e\u3067\u306e<code>-&gt;<\/code>\u3060\u3051\u306e\u4ee5\u4e0b\u306e\u5834\u5408\u3001\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u554f\u984c\u306a\u304f\u52d5\u304d\u307e\u3059\u304c\u3001\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306f\u3001<code>Attempt to read property \"name\" on null<\/code>\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<pre>\/\/ \u26a0 \u3053\u3053\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\r\n$user_name = <strong>$request-&gt;user()-&gt;name;<\/strong><\/pre>\n<p>\u305d\u306e\u305f\u3081\u3001\u3053\u308c\u307e\u3067\u306f\u4e09\u9805\u6f14\u7b97\u5b50\u3092\u4f7f\u3046\u304b<code>if\u6587<\/code>\u3067\u5206\u5c90\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre><strong>$user = $request-&gt;user();<\/strong>\r\n<strong>$user_name = !is_null($user) ? $user-&gt;name : null;<\/strong><\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u3001<code>PHP 7<\/code>\u4ee5\u964d\u306a\u3089\u300c<strong>Null Coalescing Operator<\/strong>\u300d\u3067\u3082OK\u3067\u3059\u3002<\/p>\n<pre><strong>$user_name = $request-&gt;user()-&gt;name ?? null;<\/strong><\/pre>\n<p>\u3061\u3087\u3063\u3068\u53ef\u8aad\u6027\u7684\u306b\u5927\u4e08\u592b\u304b\u306a\uff1f\u3068\u601d\u3046\u6c17\u3082\u3059\u308b\u3093\u3067\u3059\u304c\u3001\u30b3\u30fc\u30c9\u304c\u9577\u304f\u306a\u308b\u306a\u3089\u3068\u3066\u3082\u4fbf\u5229\u306a\u6c17\u304c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h1>\u30af\u30e9\u30b9\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3092\u7701\u7565\u3057\u3066\u66f8\u3051\u308b<\/h1>\n<p><code>PHP 8<\/code>\u3067\u306f\u30af\u30e9\u30b9\u5185\u3067\u4f7f\u3046\u30e1\u30f3\u30d0\u5909\u6570\u306e\u5b9a\u7fa9\u3092\u7701\u7565\u3057\u3066\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001<code>Laravel<\/code>\u306e<code>Mailable<\/code>\u3092\u4f7f\u3063\u3066\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u3053\u308c\u307e\u3067\u306e<code>PHP<\/code>\u3067\u30e1\u30f3\u30d0\u5909\u6570\u3092\u4f7f\u3046\u5834\u5408\u3001\u3088\u304f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u4e2d\u3067\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<pre>class Contacted extends Mailable\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>private User $user; <\/strong>\/\/ \ud83d\udc48 \u30e1\u30f3\u30d0\u5909\u6570\u3092\u5b9a\u7fa9\r\n\r\n    public function __construct(<strong>User $user<\/strong>)\r\n    {\r\n        <strong>$this-&gt;user = $user;<\/strong> \/\/ \ud83d\udc48 \u30e1\u30f3\u30d0\u5909\u6570\u3078\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\r\n    }<\/pre>\n<p>\u3057\u304b\u3057\u3001\u3053\u308c\u304b\u3089\u306f\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3060\u3051\u3067\u5b8c\u7d50\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>class Contacted extends Mailable\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    \/\/ \ud83d\udc48 \u30e1\u30f3\u30d0\u5909\u6570\u306e\u5b9a\u7fa9\u304c\u4e0d\u8981\r\n\r\n    public function __construct(<strong>private<\/strong> User $user) \/\/ \ud83d\udc48 private \u3084 public \u3092\u3064\u3051\u308b\u3060\u3051\r\n    {\r\n        \/\/ \ud83d\udc48 \u30e1\u30f3\u30d0\u5909\u6570\u3078\u306e\u683c\u7d0d\u3082\u4e0d\u8981\uff01\r\n    }<\/pre>\n<p>\u3064\u307e\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3068\u3066\u3082\u30b9\u30c3\u30ad\u30ea\u3057\u305f\u5f62\u3067\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>class Contacted extends Mailable<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    \/\/ \u7701\u7565<\/strong>\r\n\r\n<strong>    public function __construct(private User $user)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>    }<\/strong><\/pre>\n<p>\u3053\u308c\u307e\u3067\u6b63\u76f4\u306a\u3068\u3053\u308d\u3001\u30b3\u30b3\u306f\u3081\u3093\u3069\u3046\u3060\u3068\u611f\u3058\u3066\u3044\u305f\u90e8\u5206\u306a\u306e\u3067\u3001\u500b\u4eba\u7684\u306b\u3059\u3054\u304f\u5b09\u3057\u3044\u6a5f\u80fd\u3067\u3059\ud83d\udc4d<\/p>\n<h1>try ~ catch \u306e\u5909\u6570\u3092\u7701\u7565\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f<\/h1>\n<p>\u3053\u308c\u307e\u3067 <strong>try ~ catch<\/strong>\u3092\u4f7f\u3046\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001<code>catch()<\/code>\u306e\u4e2d\u306b\u306f\u5909\u6570\u3092\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre>try {\r\n\r\n    echo $undefined; \/\/ \u308f\u3056\u3068\u30a8\u30e9\u30fc\u3092\u767a\u751f\u3055\u305b\u308b\r\n\r\n} catch (\\Exception <strong>$exception<\/strong>) {\r\n\r\n    \/\/ \u30a8\u30e9\u30fc\u306e\u5834\u5408\r\n\r\n}<\/pre>\n<p>\u3053\u308c\u304c\u3001PHP 8\u304b\u3089\u306f\u5909\u6570\u540d\u306e\u6307\u5b9a\u306f\u4e0d\u8981\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre>try {\r\n\r\n    echo $undefined;\r\n\r\n} catch (\\Exception) { <strong>\/\/ \ud83d\udc48 \u5909\u6570\u304c\u4e0d\u8981\u306b\u306a\u308a\u307e\u3057\u305f<\/strong>\r\n\r\n    \/\/ \u30a8\u30e9\u30fc\u306e\u5834\u5408\r\n\r\n}<\/pre>\n<p>\u305d\u306e\u305f\u3081\u3001\u30a8\u30e9\u30fc\uff08\u4f8b\u5916\uff09\u306e\u4e2d\u8eab\u3092\u77e5\u308b\u5fc5\u8981\u306f\u306a\u3044\u3068\u304d\u306b\u306f\u91cd\u5b9d\u3059\u308b\u3093\u3058\u3083\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<h1>\u578b\u3092\u8907\u6570\u6307\u5b9a\u3067\u304d\u308b\u6a5f\u80fd<\/h1>\n<p><code>PHP 7.4<\/code>\u304b\u3089\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u300c<strong>\u578b\u4ed8\u304d\u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u300d\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre>class Item\r\n{\r\n    public <strong>int<\/strong> $id;\r\n    public <strong>string<\/strong> $name;\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u305d\u3057\u3066\u3001<code>PHP 8<\/code>\u304b\u3089\u306f\u3001\u8907\u6570\u306e\u578b\u3092\u5ba3\u8a00\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><code>Laravel<\/code>\u306e<code>Mailable<\/code>\u3067\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Mail;\r\n\r\nuse App\\Models\\User;\r\nuse Illuminate\\Bus\\Queueable;\r\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\r\nuse Illuminate\\Mail\\Mailable;\r\nuse Illuminate\\Queue\\SerializesModels;\r\n\r\nclass Contacted extends Mailable\r\n{\r\n    use Queueable, SerializesModels;\r\n\r\n    <strong>private string|User $user; \/\/ \ud83d\udc48 \u578b\u3092\uff12\u3064\u6307\u5b9a\u3057\u3066\u307e\u3059<\/strong>\r\n\r\n    public function __construct(<strong>string|User $user<\/strong>)<strong> \/\/ \ud83d\udc48 \u578b\u3092\uff12\u3064\u6307\u5b9a\u3057\u3066\u307e\u3059<\/strong>\r\n    {\r\n        $this-&gt;user = $user;\r\n    }\r\n\r\n    public function build()\r\n    {\r\n        $user_name = $this-&gt;user-&gt;name ?? $this-&gt;user;\r\n\r\n        return $this-&gt;to('admin@example.com')\r\n            -&gt;view('emails.contacted')\r\n            -&gt;with([\r\n                'user_name' =&gt; $user_name\r\n            ]);\r\n    }\r\n}<\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u306f\u3001\u5909\u6570<code>$user<\/code>\u306f\u300c<strong>User\u30e2\u30c7\u30eb\u304b\u3001\u6587\u5b57\u5217\u306a\u3089OK<\/strong>\u300d\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u305d\u306e\u6614<code>Java<\/code>\u3092\u66f8\u304f\u3068\u304d\u306f\u578b\u5ba3\u8a00\u306f\u5f53\u305f\u308a\u524d\u3067\u3057\u305f\u304c\u3001<code>PHP<\/code>\u3084<code>Python<\/code>\u304c\u30e1\u30a4\u30f3\u8a00\u8a9e\u306b\u306a\u3063\u3066\u304b\u3089\u306f\u3042\u307e\u308a\u4f7f\u308f\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u3001\u6b63\u76f4\u578b\u306e\u5ba3\u8a00\u306f\u3081\u3093\u3069\u3046\u3060\u306a\u3001\u306a\u3093\u3066\u601d\u3046\u3093\u3067\u3059\u304c\u7686\u3055\u3093\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u2753\u2753<\/p>\n<h1>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3067\u3082\u300c::class\u300d\u304c\u3064\u304b\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f<\/h1>\n<p>\u3053\u308c\u307e\u3067\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3089\u30af\u30e9\u30b9\u540d\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f<code>get_class()<\/code>\u3092\u5b9f\u884c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre>$user = User::find(1);\r\ndd(<strong>get_class($user)<\/strong>);<\/pre>\n<p>\u3057\u304b\u3057\u3001<code>PHP 8<\/code>\u304b\u3089\u306f\u30b7\u30f3\u30d7\u30eb\u306b<code>::class<\/code>\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre>$user = User::find(1);\r\ndump(<strong>$user::class<\/strong>);<\/pre>\n<p>\u5730\u5473\u306a\u5909\u66f4\u3067\u3059\u304c\u3001\u53ef\u8aad\u6027\u3082\u4e0a\u304c\u3063\u3066\u3044\u3044\u3068\u601d\u3044\u307e\u3059\ud83d\udc4d<\/p>\n<h1>\u53c2\u8003\u8a18\u4e8b<\/h1>\n<p>\u4eca\u56de\u3001<code>PHP 8<\/code>\u306e\u65b0\u6a5f\u80fd\u3067\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u30da\u30fc\u30b8\u306f\u4ee5\u4e0b\u306e\uff12\u3064\u3067\u3059\u3002<br \/>\n\u3053\u306e\u8a18\u4e8b\u306b\u306f\u66f8\u3044\u3066\u3044\u306a\u3044\u8a18\u4e8b\u3082\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u8208\u5473\u306e\u3042\u308b\u65b9\u306f\u305c\u3072\u3054\u89a7\u306b\u306a\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>What&#8217;s new in PHP 8\uff1a<br \/>\n<a href=\"https:\/\/stitcher.io\/blog\/new-in-php-8\">https:\/\/stitcher.io\/blog\/new-in-php-8<\/a><\/p>\n<p>\u3010PHP8.0\u3011PHP8.0\u306e\u65b0\u6a5f\u80fd<br \/>\n<a href=\"https:\/\/qiita.com\/rana_kualu\/items\/fe7998fbe773544d5d25\">https:\/\/qiita.com\/rana_kualu\/items\/fe7998fbe773544d5d25<\/a><\/p>\n<p>\u30db\u30f3\u30c8\u306b\u3001\u3053\u3046\u3044\u3046\u304d\u3063\u3061\u308a\u3068\u3057\u305f\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u304f\u308c\u308b\u65b9\u306b\u306f\u611f\u8b1d\u3057\u304b\u3042\u308a\u307e\u305b\u3093\u3002\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01<\/p>\n<p>\u6b63\u76f4\u3001\u79c1\u3082\u5f7c\u3089\u306e\u3088\u3046\u306b\u306a\u308a\u305f\u304b\u3063\u305f\u3067\u3059\u304c\u3001\u3042\u304d\u3089\u304b\u306b\u5411\u3044\u3066\u306a\u3044\u306e\u3067\u3001\u4eca\u5f8c\u3082\u300c<strong>\u3086\u308b\u30fc\u304f\u697d\u3057\u3044<\/strong>\u300d\u8a18\u4e8b\u3067\u3084\u3063\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\ud83d\udc4d<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>PHP 8<\/code>\u306e\u65b0\u6a5f\u80fd\u3092<code>Laravel<\/code>\u306e\u4e2d\u3067\u4f7f\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u4eca\u56de\u7d39\u4ecb\u3057\u305f\u4e2d\u3067\u500b\u4eba\u7684\u306b\u597d\u304d\u306a\u30e9\u30f3\u30ad\u30f3\u30b0\u3092\u3064\u3051\u308b\u3068\u3059\u308b\u3068\u3001\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u30af\u30e9\u30b9\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3092\u7701\u7565\u3057\u3066\u66f8\u3051\u308b<\/li>\n<li>try ~ catch \u306e\u5909\u6570\u3092\u7701\u7565\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f<\/li>\n<li>\u30c1\u30a7\u30fc\u30f3\u30e1\u30bd\u30c3\u30c9\u3067Null\u306a\u3089\u9014\u4e2d\u3067\u7d42\u4e86\u3059\u308b\u6a5f\u80fd<\/li>\n<\/ol>\n<p>\u3069\u3046\u3084\u3089\u79c1\u306f\u300c\u3067\u304d\u308b\u3060\u3051\u306a\u3093\u3067\u3082\u7701\u7565\u3057\u305f\u3044\u300d\u3068\u8003\u3048\u3066\u3044\u308b\u3088\u3046\u3067\u3059\uff08\u7b11\uff09<\/p>\n<p>\u307e\u3041\u3001\u30d7\u30ed\u30b0\u30e9\u30de\u306f\u300c\u697d\u3057\u3088\u3046\u3068\u3059\u308b\u4eba\u300d\u306f\u9069\u6b63\u304c\u3042\u308b\u3068\u8a00\u308f\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u300c<strong>\u30e8\u30b7\uff01<\/strong>\u300d\u3068\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4445 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png\" alt=\"\" width=\"370\" height=\"310\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2-300x251.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u73fe\u5834\u732b\u3061\u3083\u3093\u3001\u304b\u308f\u3044\u3044\u3067\u3059\u306d\ud83d\ude01\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u7686\u3055\u3093\u3082\u3088\u304f\u3054\u5b58\u77e5\u306e\u3068\u304a\u308a\u3067\u3059\u304c\u3001Larave\u3060\u3051\u3067\u306a\u304fPHP\u81ea\u4f53\u3082\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3092\u7e70\u308a\u8fd4\u3057\u3066\u3044\u3066\u3001\u5e38\u306b\u65b0\u3057\u3044\u6a5f\u80fd\u304c\u52a0\u308f\u3063\u305f\u308a\u3057\u3066\u3044\u307e\u3059\u3002 \u305d\u3057\u3066\u3001\u6765\u305f &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=8333\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;PHP 8 \u306e\u65b0\u6a5f\u80fd\u3092Laravel\u3067\u4f7f\u3063\u3066\u307f\u305f&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":8341,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,10],"tags":[227],"class_list":["post-8333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-php","tag-php-8"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8333"}],"version-history":[{"count":9,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8333\/revisions"}],"predecessor-version":[{"id":8343,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8333\/revisions\/8343"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/8341"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}