{"id":278,"date":"2023-10-29T03:00:58","date_gmt":"2023-10-28T18:00:58","guid":{"rendered":"https:\/\/shugomatsuzawa.com\/techblog\/?p=278"},"modified":"2023-10-29T03:00:59","modified_gmt":"2023-10-28T18:00:59","slug":"laravel%e3%83%a2%e3%83%87%e3%83%ab%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b5%e3%82%92%e4%bd%bf%e3%81%86%e6%96%b9%e6%b3%952%e7%a8%ae%e9%a1%9e","status":"publish","type":"post","link":"https:\/\/shugomatsuzawa.com\/techblog\/2023\/10\/29\/278\/","title":{"rendered":"Laravel\u30e2\u30c7\u30eb\u30a2\u30af\u30bb\u30b5\u3092\u4f7f\u3046\u65b9\u6cd52\u7a2e\u985e"},"content":{"rendered":"\n<p>\u65b0\u3057\u3044\u4f1a\u793e\u306b\u5165\u3063\u305f\u3082\u306e\u306e\u3001Laravel\u306a\u3093\u305e\u89e6\u3063\u305f\u3053\u3068\u304c\u306a\u3044\u306e\u3067\u3072\u305f\u3059\u3089\u52c9\u5f37\u306e\u6bce\u65e5\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001customer\u30c6\u30fc\u30d6\u30eb\u306estatus\u3068\u3044\u3046\u30ab\u30e9\u30e0\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b0,1\u306a\u3069\u306e\u6570\u5b57\u306b\u5fdc\u3058\u3066CSS\u30af\u30e9\u30b9\u3092\u51fa\u3057\u305f\u304b\u3063\u305f\u306e\u3060\u304c\u3001<br>\u6700\u521d\u306f\u6b21\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3044\u305f\u3002<\/p>\n\n\n\n<p><code>config\/const.php<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nreturn &#91;\n    'status_class' =&gt; &#91;\n        0 =&gt; 'fa-ban',\n        1 =&gt; 'fa-check',\n        2 =&gt; 'fa-circle-exclamation',\n    ],\n];<\/code><\/pre>\n\n\n\n<p><code>resources\/views\/index.blade.php<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;i class=\"fa-solid {{ config('const.status_class.' . $records-&gt;status) }}\"&gt;&lt;\/i&gt;<\/code><\/pre>\n\n\n\n<p>\u3057\u304b\u3057\u3001\u3053\u3046\u3044\u3046\u306e\u306f\u30e2\u30c7\u30eb\u30a2\u30af\u30bb\u30b5\u3092\u4f7f\u3063\u3066\u4e00\u7b87\u6240\u3067\u5b9a\u7fa9\u3057\u305f\u307b\u3046\u304c\u3044\u3044\u3068\u6559\u3048\u3066\u3082\u3089\u3063\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30e2\u30c7\u30eb\u30a2\u30af\u30bb\u30b5\u3092\u4f7f\u3046<\/h2>\n\n\n\n<p>\u30e2\u30c7\u30eb\u30a2\u30af\u30bb\u30b5\u306f\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3002<\/p>\n\n\n\n<p><code>app\/Models\/Customer.php<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\u7701\u7565...\nclass Customer extends Model\n{\n    ...\u7701\u7565...\n    public function getStatusClassAttribute()\n    {\n        $ret = 'fa-ban'\n        switch ($this-&gt;status) {\n            case 1:\n                $ret = 'fa-check';\n                break;\n            case 2:\n                $ret = 'fa-circle-exclamation';\n                break;\n        }\n        return $ret;\n    }\n}<\/code><\/pre>\n\n\n\n<p><code>resources\/views\/index.blade.php<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;i class=\"fa-solid {{ $records-&gt;status_class }}\"&gt;&lt;\/i&gt;<\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u5834\u5408<code>status_class<\/code>\u3068\u3044\u3046\u30ab\u30e9\u30e0\u540d\u3067CSS\u30af\u30e9\u30b9\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<br>\u30e2\u30c7\u30eb\u5074\u306f<code>get\u4f5c\u6210\u3057\u305f\u3044\u30ab\u30e9\u30e0\u540d\u306e\u30ad\u30e3\u30e1\u30eb\u30b1\u30fc\u30b9Attribute()<\/code>\u3067\u5b9a\u7fa9\u3059\u308b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f59\u8ac7<\/h2>\n\n\n\n<p>\u3061\u306a\u307f\u306b\u3053\u3093\u306a\u66f8\u304d\u65b9\u3082\u3067\u304d\u308b\u3089\u3057\u3044\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>...\u7701\u7565...\nclass Customer extends Model\n{\n    ...\u7701\u7565...\n    public function StatusClass(): Attribute {\n<code>        ...\u7701\u7565...<\/code>    }\n}<\/code><\/code><\/pre>\n\n\n\n<p>\u3053\u3063\u3061\u306e\u65b9\u304c\u3069\u3053\u307e\u3067\u304c\u30ab\u30e9\u30e0\u540d\u304b\u5206\u304b\u308a\u6613\u3044\u3068\u3044\u3046\u5834\u5408\u3082\u3042\u308b\u304b\u3082\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c2\u8003<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/qiita.com\/hitochan\/items\/9cd9f2cbbbdd35916a96\" data-type=\"URL\" data-id=\"https:\/\/qiita.com\/hitochan\/items\/9cd9f2cbbbdd35916a96\" target=\"_blank\" rel=\"noreferrer noopener\">\u3010Laravel\u3011\u30a2\u30af\u30bb\u30b5\u3001\u30df\u30e5\u30fc\u30c6\u30bf\u306e\u57fa\u672c\u306e\u30ad #PHP &#8211; Qiita<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u65b0\u3057\u3044\u4f1a\u793e\u306b\u5165\u3063\u305f\u3082\u306e\u306e\u3001Laravel\u306a\u3093\u305e\u89e6\u3063\u305f\u3053\u3068\u304c\u306a\u3044\u306e\u3067\u3072\u305f\u3059\u3089\u52c9\u5f37\u306e\u6bce\u65e5\u3067\u3042\u308b\u3002 \u4f8b\u3048\u3070\u3001customer\u30c6\u30fc\u30d6\u30eb\u306estatus\u3068\u3044\u3046\u30ab\u30e9\u30e0\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b0,1\u306a\u3069\u306e\u6570\u5b57\u306b\u5fdc\u3058\u3066CSS\u30af\u30e9\u30b9\u3092\u51fa\u3057\u305f\u304b\u3063\u305f\u306e [&hellip;]","protected":false},"author":1,"featured_media":280,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[39],"tags":[81,10],"class_list":["post-278","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backend","tag-laravel","tag-memo"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2023\/10\/coding-699318_1280.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/posts\/278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/comments?post=278"}],"version-history":[{"count":3,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/posts\/278\/revisions"}],"predecessor-version":[{"id":282,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/posts\/278\/revisions\/282"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/media\/280"}],"wp:attachment":[{"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/media?parent=278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/categories?post=278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/tags?post=278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}