備忘録

調べものするときは、必ずストップウォッチ使う。

https://twitter.com/59e592291982460/status/1035855374694273024

```php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;

```

```php
<?php

use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class UsersTableSeeder extends Seeder {
  /**
   * Run the database seeds.
   *
   * @return void
   */
  public function run() {
    DB::statement('SET FOREIGN_KEY_CHECKS=0');
    DB::table('users')->truncate();
    DB::statement('SET FOREIGN_KEY_CHECKS=1');

    for ($i = 0; $i < 3; $i++) {
      DB::table('users')->insert([
        'name' => 'user_name_' . $i,
        'score' => 0,
        'email' => 'user_name_' . $i . '@gmail.com',
        'password' => bcrypt('pass_' . $i),
        'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
        'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
      ]);
    }
  }
}

```

appディレクトリにincludes作って、include app_path() . '/includes/variables.php';

send ajax with array in ajax, then laravel controller.

```php
$where_ins = explode(',', $request->showed_unread_ids);
    Notice::whereIn('id', $where_ins)
      ->update(array('is_already_read' => 1));
```

```javascript
{
  "window.zoomLevel": -1,
  "editor.tabSize": 2,
  "phpfmt.psr2": false,
  "phpfmt.indent_with_space": 2,
  "beautify.language": {
    "js": {
      "type": [
        "javascript",
        "json",
        "jsonc"
      ],
      "filename": [
        ".jshintrc",
        ".jsbeautifyrc"
      ]
    },
    "css": [
      "css",
      "scss"
    ],
    "html": [
      "htm",
      "html",
      "blade"
    ],
  },
  "editor.insertSpaces": false,
	"editor.detectIndentation": false,
	"editor.autoIndent": false,
	"workbench.activityBar.visible": true,
	"workbench.statusBar.visible": true,
	"editor.minimap.enabled": false
}
```

```html
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- CSRF Token -->
  <meta name="csrf-token" content="{{ csrf_token() }}">

  <title>{{ config('app.name', 'Laravel') }}</title>

  <!-- Fonts -->
  <link rel="dns-prefetch" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">

  <!-- Styles -->
  @section('csses')
  <link rel="stylesheet" href="{{ asset('/css/app.css') }}">
  <link rel="stylesheet" href="{{ asset('/css/my.css') }}">
  @show
</head>

<body>
  <div id="app">
    <nav class="navbar navbar-expand-md navbar-light navbar-laravel my-navbar">
      <div class="container-fluid mx-5">
        <a class="navbar-brand btn brand-btn" href="{{ url('/') }}">
          {{ __('Teratail') }}
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
          <span class="navbar-toggler-icon"></span>
        </button>

        <form class="d-flex w-25" action="{{ route('questions_search') }}" method="GET">
          <input type="text" class="form-control form-control-sm w-100" name="q" placeholder="キーワードで検索">
          <button type="submit" class="btn btn-sm btn-primary">Search</button>
        </form>

        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <!-- Left Side Of Navbar -->
          <ul class="navbar-nav mr-auto">

          </ul>

          <!-- Right Side Of Navbar -->
          <ul class="navbar-nav ml-auto d-flex align-items-center">
            <!-- Authentication Links -->
            @guest
            <li class="nav-item">
              <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
            </li>
            <li class="nav-item">
              @if (Route::has('register'))
              <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
              @endif
            </li>
            @else
            <a class="btn btn-success mr-2" href="{{ route('questions_input') }}">質問する</a>
            <b-btn ref="ex_popover_bottom" :id="'ex_popover-bottom'" variant="primary">
              N(@{{ unread_notice_ids.length }})
            </b-btn>
            <b-popover ref="notice_popover" @shown="mark_as_read" :target="'ex_popover-bottom'" :placement="'bottom'" title="お知らせ一覧" triggers="click">
              <ul class="notices">
                @forelse ($notices as $notice)
                <li class="mb-3">
                  <div class="font-weight-bold">あなたの質問に回答がありました</div>
                  <div>{{ $notice->title }}</div>
                  <div class="fz-10 d-flex justify-content-between">
                    <span>1週間前</span>
                    <span>{{ $notice->notifier_name }}さん</span>
                  </div>
                </li>
                @empty
                <li class="mb-3">
                  <div class="font-weight-bold">まだお知らせがありません。</div>
                </li>
                @endforelse
              </ul>
            </b-popover>
            <li class="nav-item dropdown">
              <div>
                <b-dropdown id="ddown1" text="{{ Auth::user()->name }}" class="m-md-2">
                  <b-dropdown-item href="{{ route('logout') }}" @click="submit_logout">{{ __('Logout') }}</b-dropdown-item>
                </b-dropdown>
              </div>

              <form id="logout-form" ref="logout_form" action="{{ route('logout') }}" method="POST" style="display: none;">
                @csrf
              </form>
        </div>
        </li>
        @endguest
        </ul>
      </div>
    </nav>

    <main class="py-4">
      @yield('content')
    </main>
  </div>

  <!-- Scripts -->
  @section('scripts')
  <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
  <script src="{{ asset('/js/lib/lodash.min.js') }}"></script>
  <script src="{{ asset('/js/lib/marked.min.js') }}"></script>
  <script src="{{ asset('/js/contents/renderer.js') }}"></script>
  <script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
  <script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
  <script src="{{ asset('/js/my_app.js') }}"></script>
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  @show
</body>

</html>


```