{"id":4855,"date":"2019-10-31T00:09:40","date_gmt":"2019-10-30T15:09:40","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=4855"},"modified":"2019-10-31T00:09:40","modified_gmt":"2019-10-30T15:09:40","slug":"%e3%81%99%e3%81%90%e3%81%a7%e3%81%8d%e3%82%8b%ef%bc%81laravel%e3%81%a8select2%e3%82%92ajax%e3%81%a7%e9%80%a3%e6%90%ba%e3%81%95%e3%81%9b%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=4855","title":{"rendered":"\u3059\u3050\u3067\u304d\u308b\uff01Laravel\u3068select2\u3092Ajax\u3067\u9023\u643a\u3055\u305b\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u6700\u8fd1\u3053\u306e\u30d6\u30ed\u30b0\u3067\u306f<code>Vue<\/code>\u306f\u57fa\u672c\u3068\u3057\u3064\u3064\u3082<strong>\u300cjQuery\u306e\u512a\u79c0\u306a\u30d7\u30e9\u30b0\u30a4\u30f3\u306f\u3069\u3093\u3069\u3093\u4f7f\u3063\u3066\u3044\u3053\u3046\u300d<\/strong>\u3068\u3044\u3046\u6d41\u308c\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u306e\u3082\u3001\u6700\u8fd1\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u696d\u754c\u306f\u30c8\u30e9\u30f3\u30b9\u30d1\u30a4\u30eb\u3001\u30d3\u30eb\u30c9\u306a\u3069\u8907\u96d1\u306b\u306a\u308a\u3059\u304e\u3066\u3057\u307e\u3063\u3066\u300c\u305d\u308c\u3063\u3066\u30db\u30f3\u30c8\u306b\u52b9\u7387\u7684\u306a\u306e\u304b\u306a\uff1f\uff1f\uff1f\u300d\u3068\u3044\u3046\u7591\u554f\u304c\u306a\u304f\u3082\u306a\u3044\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u203b \u7279\u306b<code>npm run watch<\/code>\u306e\u81ea\u52d5\u30d3\u30eb\u30c9\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u78ba\u8a8d\u3059\u308b\u307e\u3067\u306b\u591a\u5c11\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u958b\u767a\u30c6\u30f3\u30dd\u304c\u60aa\u304f\u306a\u308b\u3093\u3067\u3042\u307e\u308a\u597d\u304d\u3058\u3083\u306a\u3044\u3093\u3067\u3059\u30fb\u30fb\u30fb\ud83d\ude23<\/p>\n<p>\u305d\u3057\u3066\u3001<code>jQuery<\/code>\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u4e2d\u3067\u6c17\u306b\u5165\u3063\u3066\u3044\u308b\u306e\u304c<a href=\"https:\/\/select2.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">select2<\/a>\u3067\u3059\u3002<\/p>\n<p><code>select2<\/code>\u306f\u901a\u5e38\u306e\u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u306b\u691c\u7d22\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u3067\u3001\u7279\u306b\u9078\u629e\u80a2\u304c\u305f\u304f\u3055\u3093\u3042\u308b\u5834\u5408\u306f\u3068\u3066\u3082\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<p>\u3053\u3093\u306a\u30ab\u30f3\u30b8\u3067\u3059\u3002<br \/>\n\u2193\u2193\u2193<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4856\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/10\/select2_ajax_1.png\" alt=\"\" width=\"268\" height=\"282\" \/><\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f\u3053\u306e<code>select2<\/code>\u3092\u3001<code>Ajax<\/code>\u3092\u901a\u3057\u3066<code>Laravel<\/code>\u3068\u9023\u643a\u3055\u305b\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\uff08\u6700\u5f8c\u306b\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\uff09<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3405 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png\" alt=\"\" width=\"310\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png 310w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18-291x300.png 291w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 6.x<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4eca\u56de\u958b\u767a\u3059\u308b\u5185\u5bb9\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>users\u30c6\u30fc\u30d6\u30eb\u306b\u3042\u308b\u30c7\u30fc\u30bf\u3092select2\u3067\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<\/li>\n<li>\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u306fAjax\u3067\u53d6\u5f97\u3059\u308b<\/li>\n<li>\u4e00\u6c17\u306b\u30c7\u30fc\u30bf\u53d6\u5f97\u3059\u308b\u3068\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u60aa\u304f\u306a\u308b\u306e\u3067\u3001\uff11\u56de\u306b\u3064\u304d10\u4ef6\u305a\u3064\u53d6\u5f97<\/li>\n<li>Ajax\u3067\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u306fJavaScript\u306e\u4e2d\u3067\u52a0\u5de5\u3059\u308b<\/li>\n<li>\uff08\u304a\u307e\u3051\u3067\uff09\u65e5\u672c\u8a9e\u5316\u3001\u30af\u30ea\u30a2\u3092\u53ef\u80fd\u306b\u3059\u308b<\/li>\n<\/ul>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u203b \u306a\u304a\u3001DB\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u304c\u3042\u308b\u3053\u3068\u304c\u524d\u63d0\u3067\u3059\u3002\u3082\u3057\u307e\u3060\u7528\u610f\u3057\u3066\u3044\u306a\u3044\u65b9\u306f\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=4576\">Laravel6.0\u3067\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u4f7f\u3046\u65b9\u6cd5<\/a>\uff08<code>Laravel 6<\/code>\u4ee5\u4e0a\uff09\u304b<a href=\"https:\/\/blog.capilano-fw.com\/?p=289\">\u3010Laravel5.6\u3011\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u76f4\u5f8c\u306b\u3084\u308b\u3053\u3068\uff13\u70b9<\/a>\uff08\u305d\u308c\u3088\u308a\u6614\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\uff09\u3092\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4858\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/10\/select2_ajax_3.png\" alt=\"\" width=\"565\" height=\"464\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/10\/select2_ajax_3.png 565w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/10\/select2_ajax_3-300x246.png 300w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/p>\n<h1>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u307e\u305a\u306f\u3001<code>routes\/web.php<\/code>\u3092\u958b\u3044\u3066\u6b21\u306e\u30eb\u30fc\u30c8\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>Route::get('select2_ajax', 'HomeController@select2_ajax');<\/strong>\r\n<strong>Route::get('ajax\/user', 'Ajax\\UserController@index');<\/strong><\/pre>\n<p>\u4e0a\u304c\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30da\u30fc\u30b8\u3067\u3001\u4e0b\u304c<code>Ajax<\/code>\u3067\u30c7\u30fc\u30bf\u53d6\u5f97\uff08\u691c\u7d22\uff09\u3059\u308b\u3082\u306e\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u306f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u5f8c\u3067\u7ba1\u7406\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u3001\uff12\u3064\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u5206\u3051\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u3059\u3067\u306b\u5b58\u5728\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u7701\u7565\u3057\u3066\u3082OK\u3067\u3059\uff09<\/p>\n<pre><strong>php artisan make:controller HomeController<\/strong><\/pre>\n<p>\u4e2d\u306b<code>select2_ajax()<\/code>\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Http\\Controllers;\r\nuse Illuminate\\Http\\Request;\r\n\r\nclass HomeController extends Controller\r\n{\r\n    \/\/ \u7701\u7565\r\n    <strong>public function select2_ajax() {<\/strong>\r\n\r\n<strong>        return view('select2_ajax');<\/strong>\r\n\r\n<strong>    }<\/strong><\/pre>\n<p>\u7d9a\u3044\u3066<code>Ajax<\/code>\u90e8\u5206\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u3059\u3002\uff08\u4eca\u56de\u306f\u30e6\u30fc\u30b6\u30fc\u3092\u9078\u629e\u3059\u308b\u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u306a\u306e\u3067<code>UserController<\/code>\u3068\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u540d\u524d\u306f\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n<pre><strong>php artisan make:controller Ajax\\\\UserController<\/strong><\/pre>\n<p>\u4e2d\u8eab\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Http\\Controllers\\Ajax;\r\n\r\nuse App\\Http\\Controllers\\Controller;\r\nuse Illuminate\\Http\\Request;\r\n\r\nclass UserController extends Controller\r\n{\r\n    <strong>public function index(Request $request) {<\/strong>\r\n\r\n<strong>        $query = \\App\\User::query();<\/strong>\r\n\r\n<strong>        if($request-&gt;filled('q')) {<\/strong>\r\n\r\n<strong>            $keywords = explode(' ', trim(mb_convert_kana($request-&gt;q, 's')));<\/strong>\r\n\r\n<strong>            foreach($keywords as $keyword) {<\/strong>\r\n\r\n<strong>                $query-&gt;where('name', 'LIKE', '%'. $keyword .'%');<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        $per_page = 10;<\/strong>\r\n<strong>        return $query-&gt;paginate($per_page);<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u307e\u305a\u3001<code>select2<\/code>\u304b\u3089\u9001\u3089\u308c\u3066\u304f\u308b<code>q<\/code>\u3068\u3044\u3046\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u691c\u7d22\u30ad\u30fc\u30ef\u30fc\u30c9\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u308c\u3092\u4f7f\u3063\u3066<code>users<\/code>\u306e\u30c7\u30fc\u30bf\u691c\u7d22\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u203b \u4eca\u56de\u306f<code>name<\/code>\u306e\u307f\u3067\u306e\u691c\u7d22\u3067\u3059\u304c\u3001\u304a\u597d\u307f\u3067\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3084\u96fb\u8a71\u756a\u53f7\u3082\u542b\u3081\u3066\u691c\u7d22\u3057\u3066\u3082\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u3055\u3089\u306b\u3001<code>$per_page<\/code>\u304c\uff11\u56de\u306e\u30a2\u30af\u30bb\u30b9\u3054\u3068\u306b\u4f55\u4ef6\u53d6\u5f97\u3059\u308b\u304b\u3068\u3044\u3046\u6570\u5b57\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u3053\u3082\u304a\u597d\u307f\u3067\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u6700\u5f8c\u306b\u30d3\u30e5\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><code>resources\/views\/select2_ajax.blade.php<\/code>\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n    <strong>&lt;link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/select2\/4.0.10\/css\/select2.min.css\"&gt;<\/strong>\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;div&gt;\r\n        <strong>&lt;select style=\"width:250px;\" class=\"select2-ajax\"&gt;&lt;\/select&gt;<\/strong>\r\n    &lt;\/div&gt;\r\n    <strong>&lt;script src=\"https:\/\/code.jquery.com\/jquery-3.4.1.min.js\"&gt;&lt;\/script&gt;<\/strong>\r\n<strong>    &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/select2\/4.0.10\/js\/select2.min.js\"&gt;&lt;\/script&gt;<\/strong>\r\n    &lt;script&gt;\r\n\r\n        \/\/ \u30da\u30fc\u30b8\u304c\u8aad\u307f\u8fbc\u307e\u308c\u305f\u3089\u5b9f\u884c\r\n        $(() =&gt; {\r\n\r\n            <strong>$('.select2-ajax').select2({<\/strong>\r\n<strong>                ajax: {<\/strong>\r\n<strong>                    url: '\/ajax\/user',<\/strong>\r\n<strong>                    dataType: 'json',<\/strong>\r\n<strong>                    processResults(response) {  \/\/ \u30c7\u30fc\u30bf\u3092select2\u5411\u3051\u306b\u52a0\u5de5<\/strong>\r\n\r\n<strong>                        let options = [];<\/strong>\r\n\r\n<strong>                        response.data.forEach((user) =&gt; {<\/strong>\r\n\r\n<strong>                            options.push({<\/strong>\r\n<strong>                                id: user.id,<\/strong>\r\n<strong>                                text: user.name<\/strong>\r\n<strong>                            });<\/strong>\r\n\r\n<strong>                        });<\/strong>\r\n\r\n<strong>                        return {<\/strong>\r\n<strong>                            results: options,<\/strong>\r\n<strong>                            pagination: {<\/strong>\r\n<strong>                                more: (response.next_page_url !== null)  \/\/ \u6b21\u30da\u30fc\u30b8\u304c\u3042\u308b\u304b\u3069\u3046\u304b<\/strong>\r\n<strong>                            }<\/strong>\r\n<strong>                        };<\/strong>\r\n\r\n<strong>                    }<\/strong>\r\n<strong>                }<\/strong>\r\n<strong>            });<\/strong>\r\n\r\n        });\r\n\r\n    &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u307e\u305a\u3001<code>select2<\/code>\u3092\u4f7f\u3046\u305f\u3081\u306b\u5fc5\u8981\u306a\u4f5c\u696d\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>cdn \u3067 jQuery \u3068 select2 \u3092\u8aad\u307f\u8fbc\u3080<\/li>\n<li>&lt;select&gt; \u301c &lt;\/select&gt; \u30bf\u30b0\u3092\u3064\u304f\u308b<\/li>\n<li>select2() \u30e1\u30bd\u30c3\u30c9\u3067\u3001select2\u3092\u8d77\u52d5<\/li>\n<\/ul>\n<p>\u305d\u3057\u3066<code>select2<\/code>\u3067<code>Ajax<\/code>\u3092\u4f7f\u3046\u305f\u3081\u306b\u306f\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u5185\u306b\u4ee5\u4e0b\uff13\u3064\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u5024\u3092\u542b\u3093\u3060<code>ajax<\/code>\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>url\u3000\u30fb\u30fb\u30fb\u3000Ajax\u3067\u30c7\u30fc\u30bf\u53d6\u5f97\u3059\u308b\u30da\u30fc\u30b8\u306eURL<\/li>\n<li>dataType\u3000\u30fb\u30fb\u30fb\u3000\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u3002\u7701\u7565\u3059\u308b\u3068<code>json<\/code>\u306b\u306a\u308b\u307f\u305f\u3044\u3067\u3059\u3002<\/li>\n<li>processResults\u3000\u30fb\u30fb\u30fb\u3000Ajax\u3067\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092\u52a0\u5de5\u3059\u308b\u30e1\u30bd\u30c3\u30c9<\/li>\n<\/ul>\n<p>\u3053\u3053\u3067\u4e00\u756a\u91cd\u8981\u306a\u306e\u304c<code>processResults<\/code>\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u4e2d\u3067<code>Laravel<\/code>\u304b\u3089<code>Ajax<\/code>\u3092\u901a\u3057\u3066\u63d0\u4f9b\u3055\u308c\u308b\u30c7\u30fc\u30bf\u3092<code>select2<\/code>\u5411\u3051\u306b\u52a0\u5de5\u3057\u3066\u3044\u307e\u3059\u3002\uff08\u3064\u307e\u308a\u3001<code>Laravel<\/code>\u5074\u3067<code>id<\/code> &amp; <code>text<\/code>\u306e\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b\u306a\u3089\u3053\u3053\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\uff09<\/p>\n<p>\u307e\u305f\u3001<code>pagination<\/code>\u30d1\u30e9\u30e1\u30fc\u30bf\u306e<code>more<\/code>\u306f\u3001<strong>\u300c\u307e\u3060\u6b8b\u308a\u306e\u30c7\u30fc\u30bf\u304c\u5b58\u5728\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u300d<\/strong>\u3068\u3044\u3046\u610f\u5473\u3067\u3001\u307e\u3060\u6b8b\u3063\u3066\u3044\u308b\u306a\u3089<code>select2<\/code>\u306f\u30da\u30fc\u30b8\u756a\u53f7\u3092\u5897\u3084\u3057\u3066\u518d\u5ea6Ajax\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3092\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u203b \u306a\u304a\u3001<code>select2<\/code>\u3082<code>Laravel<\/code>\u3082\u30da\u30fc\u30b8\u756a\u53f7\u306b\u306f<code>page<\/code>\u3068\u3044\u3046\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u306e\u90e8\u5206\u306f\u52a0\u5de5\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<h1>\u304a\u307e\u3051<\/h1>\n<p>\u3067\u306f\u3001\u305b\u3063\u304b\u304f\u3053\u3053\u307e\u3067<code>select2<\/code>\u3067\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u4f5c\u3063\u3066\u304d\u305f\u306e\u3067\u3001\u304a\u307e\u3051\u3068\u3057\u3066\u6b21\u306e\uff12\u3064\u3082\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li>\u65e5\u672c\u8a9e\u5316<\/li>\n<li>\u9078\u629e\u3055\u308c\u305f\u3082\u306e\u3092\u30af\u30ea\u30a2\u53ef\u80fd\u306b\u3059\u308b<\/li>\n<\/ul>\n<p>\u307e\u305a\u65e5\u672c\u8a9e\u5316\u3059\u308b\u306b\u306f\u3001\u5c02\u7528\u306e<code>cdn<\/code>\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u305d\u308c\u3092\u8ffd\u52a0\u3067\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<pre>&lt;script src=\"https:\/\/code.jquery.com\/jquery-3.4.1.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/select2\/4.0.10\/js\/select2.min.js\"&gt;&lt;\/script&gt;\r\n<strong>\r\n&lt;!-- \u3053\u3053\u3092\u8ffd\u52a0 --&gt;\r\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/select2\/4.0.10\/js\/i18n\/ja.js\"&gt;&lt;\/script&gt;<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001<code>select2<\/code>\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306b<code>language<\/code>\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<pre>$('.select2-ajax').select2({\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>language: 'ja' \/\/ \u65e5\u672c\u8a9e\u5316<\/strong>\r\n});<\/pre>\n<p>\u7d9a\u3044\u3066\u30af\u30ea\u30a2\u3092\u53ef\u80fd\u306b\u3059\u308b\u306b\u306f\u3001\u30aa\u30d7\u30b7\u30e7\u30f3\u306e<code>allowClear<\/code>\u3068<code>placeholder<\/code>\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>$('.select2-ajax').select2({\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n<strong>    allowClear: true,<\/strong>\r\n<strong>    placeholder: ''<\/strong>\r\n});<\/pre>\n<p>\u4e00\u898b<code>allowClear<\/code>\u3060\u3051\u3067\u826f\u3055\u305d\u3046\u306a\u3082\u306e\u3067\u3059\u304c\u3001\u5b9f\u306f<code>placeholder<\/code>\u3068\u30da\u30a2\u306b\u306a\u3063\u3066\u3044\u308b\u3089\u3057\u304f\u5358\u4f53\u3067\u306f\u3046\u307e\u304f\u3044\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u3053\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u3064\u3051\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30af\u30ea\u30a2\u30de\u30fc\u30af\u304c\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4857\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/10\/select2_ajax_2.png\" alt=\"\" width=\"461\" height=\"88\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/10\/select2_ajax_2.png 461w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/10\/select2_ajax_2-300x57.png 300w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u4eca\u56de\u958b\u767a\u3057\u305f\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><iframe loading=\"lazy\" title=\"Laravel\u3068select2\u3092Ajax\u3067\u9023\u643a\u3055\u305b\u305f\u30b5\u30f3\u30d7\u30eb\" width=\"525\" height=\"394\" src=\"https:\/\/www.youtube.com\/embed\/zT1AZ1ZTlyY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>\u306f\u3044\uff01\u3046\u307e\u304f\u3044\u304d\u307e\u3057\u305f\ud83d\ude0a\u2728<\/p>\n<h1>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30b3\u30fc\u30c9\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b \u305f\u3060\u3057\u3001<code>users<\/code>\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u306f\u3054\u81ea\u8eab\u3067\u7528\u610f\u3057\u3066\u3044\u305f\u3060\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=4859&amp;tmstv=1777433099\" rel=\"nofollow\" id=\"download-link-4859\" data-redirect=\"false\" >\n\tLaravel\u3068select2\u3092Ajax\u3067\u9023\u643a<\/a>\n\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Laravel<\/code>\u3068<code>select2<\/code>\u3092<code>Ajax<\/code>\u3067\u9023\u643a\u3055\u305b\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u30b5\u30a4\u30c8\u904b\u55b6\u3092\u9577\u304f\u7d9a\u3051\u3066\u3044\u308b\u3068\u3001\u3069\u3046\u3057\u3066\u3082\u30c7\u30fc\u30bf\u304c\u5897\u3048\u3066\u3057\u307e\u3044\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u843d\u3061\u3066\u3057\u307e\u3046\u3053\u3068\u306f\u3088\u304f\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u3053\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u3063\u3066\u3088\u308a\u9ad8\u901f\u306b\u3001\u3088\u308a\u4f7f\u3044\u3084\u3059\u3044\u9078\u629e\u6a5f\u80fd\u3092\u4f5c\u3063\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u79c1\u304c\u30e1\u30a4\u30f3\u3067\u4f7f\u3063\u3066\u3044\u308bVue\u3068\u9023\u643a\u3055\u305b\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u3082\u3057\u8208\u5473\u304c\u3042\u308b\u65b9\u306f\u904e\u53bb\u8a18\u4e8b\u306e<a href=\"https:\/\/blog.capilano-fw.com\/?p=2815\">\u3059\u3050\u3067\u304d\u308b\uff01Vue\u3068jQuery\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u9023\u643a\u3055\u305b\u308b\u65b9\u6cd5<\/a>\u3092\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-428 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/30.png\" alt=\"\" width=\"205\" height=\"350\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/30.png 205w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/30-176x300.png 176w\" sizes=\"auto, (max-width: 205px) 100vw, 205px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u6700\u8fd1\u3053\u306e\u30d6\u30ed\u30b0\u3067\u306fVue\u306f\u57fa\u672c\u3068\u3057\u3064\u3064\u3082\u300cjQuery\u306e\u512a\u79c0\u306a\u30d7\u30e9\u30b0\u30a4\u30f3\u306f\u3069\u3093\u3069\u3093\u4f7f\u3063\u3066\u3044\u3053\u3046\u300d\u3068\u3044\u3046\u6d41\u308c\u304c\u3042\u308a\u307e\u3059\u3002 \u3068\u3044\u3046\u306e\u3082\u3001\u6700\u8fd1\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=4855\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u3059\u3050\u3067\u304d\u308b\uff01Laravel\u3068select2\u3092Ajax\u3067\u9023\u643a\u3055\u305b\u308b\u65b9\u6cd5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":4865,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[129,3],"tags":[181],"class_list":["post-4855","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery","category-laravel","tag-select2"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4855","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=4855"}],"version-history":[{"count":4,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4855\/revisions"}],"predecessor-version":[{"id":4866,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4855\/revisions\/4866"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/4865"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}