スポンサーサイト

2023.04.20 Thursday
0

    一定期間更新がないため広告を表示しています

    category:- | by:スポンサードリンク | - | - | -

    lalala

    2016.11.13 Sunday 21:17
    0
      スクロールするかな

      ・repositoryでパラメータなかったらシステムエラーにするかな
      ・owlでテスト参考
      ・logo表示確認 → サイドバー固定やめようかね
      ・お知らせ確認
      ・modelをまとめる
      ・inputとreqの統一
      ・mock
      ・laravel ログ IPアドレス 端末
      Request::ip()



      ・コントローラーではやっぱり コンストラクタでつくった $this-> をつかおう
      blog.comnect.net/blog/131

      ルーティング
      prefixやドメイン名でグルーピングできたり、ルーティングでMiddlewareを足したりできるのでかなり優秀。
      LaravelCollectiveを使えばannotationで指定もできる。自分は使っていない。
      Middlewareというのはいわゆるフィルタ的な、共通の事前処理のようなもの。認証チェックとか
      ビューの共通変数を当てたりするのに使うことが多い。

      http://qiita.com/wrbss/items/6b8c80892299dc2ba5f2

      VIEWで ENV{'HOME_URL'}つかってるがどうやって設定してるんだっけ?
      http://qiita.com/wrbss/items/6b8c80892299dc2ba5f2

      ・view共通変数
      コンストラクタで以下のように書くと blog.index、blog.show、blog.editのviewへ渡せると思います。
      public function __construct() {
      View::share('categories', 'カテゴリ');
      }

      たとえば特定の一連のURIにおいて同じビュー変数を設定したいときなどはView::share()を使う。
      View::share("name", "foobar");
      指定する場所としては、App::beforeとか、特定のフィルタなんかが考えられる。同じ処理を何度も書きたくないとか、フィルタで一度引っ張ったデータをコントローラで再度引っ張ってて無駄っぽいと感じた時などに使うと幸せになれるかもしれない。
      App::before(function($request)
      {
      View::share('something', Something::find(1));
      });


      http://syossan.hateblo.jp/entry/2014/05/26/104254
      こうやってるかの確認
      DB::transactionを使うとエラーになった場合自動でロールバックまで行ってくれるので便利ですねー!
      なので、LaravelでDB処理を書く際は以下のように書くのが良いみたいです。
      $table = Table::find(1);
      DB::transaction(function() use($table) {
      // InsertとかupdateとかのDB処理
      $table->save();
      });

      repositoryにエラー処理書いてないのが多いね

      こんな感じの画面を作るので以下のメソッドを用意することにします。

      index => 一覧画面表示処理
      create => 新規作成画面表示処理
      store => 新規作成処理
      edit => 更新画面表示処理
      update => 更新処理
      delete => 削除処理
      check => TODOをチェックする処理



      model
      app/Todo.php


      <?php namespace App;

      use Illuminate¥Database¥Eloquent¥Model;

      class Todo extends Model {

      protected $table = 'todos';

      protected $fillable = ['title', 'limit', 'done', 'user_id'];

      protected $dates = ['limit'];

      public function user()
      {
      return $this->belongsTo('App¥User');
      }
      }

      ルートパラメータが必須でない場合、後ろに?をつけます。
      routes.php
      Route::get('item/{id?}', function ($id = null) {
      return '商品ID: ' . $id;
      });


      idはvalue等ではなくurlに含んで送る(POSTの場合も)。
      削除(destroy)は、リンク(GET)ではなくPOSTで処理する。idはurlで送る。
      削除ボタンにbtn-destroyというクラスを追加。

      リクエスト参考かな
      http://qiita.com/zaburo/items/9fefa3f6834b2e79b734

      書き方さんこうに コメントとか
      https://github.com/bestmomo/laravel5-example/blob/master/app/Repositories/UserRepository.php




      owl
      request ではなく input で統一したほうがいいのかな?





      ツインバード サイクロンスティック型クリーナー スケルトンブラック TC-E123SBK
      ツインバード工業(TWINBIRD) (2012-09-14)売り上げランキング: 30



      category:Laravel | by:ittoocomments(0)trackbacks(0) | -

      laravel middlewareで共通処理

      2016.11.13 Sunday 13:56
      0
        やること

        Middlewareを作成する
        作成したMiddlewareをKernelに追加する
        Middlewareを作成する

        今回はすべてのviewで使っているデータを渡すミドルウェアを作ってみる。

        $ php artisan make:middleware Views
        1
        $ php artisan make:middleware Views
        app/Http/MiddlewareにViews.phpが作成される。

        デフォルトがこれ。


        <?php

        namespace App¥Http¥Middleware;

        use Closure;

        class Views
        {
        /**
        * Handle an incoming request.
        *
        * @param ¥Illuminate¥Http¥Request $request
        * @param ¥Closure $next
        * @return mixed
        */
        public function handle($request, Closure $next)
        {
        return $next($request);
        }
        }

        <?php

        namespace App¥Http¥Middleware;

        use Closure;

        class Views
        {
        /**
        * Handle an incoming request.
        *
        * @param ¥Illuminate¥Http¥Request $request
        * @param ¥Closure $next
        * @return mixed
        */
        public function handle($request, Closure $next)
        {
        return $next($request);
        }
        }
        handle()にいろいろ追記していく。

        View::share()を使って、とりあえずログインユーザ名を渡してみる。


        <?php

        namespace App¥Http¥Middleware;

        use Closure;

        class Views
        {
        /**
        * Handle an incoming request.
        *
        * @param ¥Illuminate¥Http¥Request $request
        * @param ¥Closure $next
        * @return mixed
        */
        public function handle($request, Closure $next)
        {
        //ユーザ名をviewに渡す
        ¥View::share('username', ¥Auth::user()->name);

        return $next($request);
        }
        }

        <?php

        namespace App¥Http¥Middleware;

        use Closure;

        class Views
        {
        /**
        * Handle an incoming request.
        *
        * @param ¥Illuminate¥Http¥Request $request
        * @param ¥Closure $next
        * @return mixed
        */
        public function handle($request, Closure $next)
        {
        //ユーザ名をviewに渡す
        ¥View::share('username', ¥Auth::user()->name);

        return $next($request);
        }
        }
        ミドルウェアはこれでOK.

        MiddlewareをKernelに追加する

        ミドルウェアを作っただけでは呼べないので Kernel.php の $routeMiddleware に追記して呼び出せるようにする。

        app/Http/Kernel.php


        /**
        * アプリケーションのルートミドルウェアスタック
        *
        * These middleware may be assigned to groups or used individually.
        *
        * @var array
        */
        protected $routeMiddleware = [
        'auth' => ¥App¥Http¥Middleware¥Authenticate::class,
        'auth.basic' => ¥Illuminate¥Auth¥Middleware¥AuthenticateWithBasicAuth::class,
        'guest' => ¥App¥Http¥Middleware¥RedirectIfAuthenticated::class,
        'throttle' => ¥Illuminate¥Routing¥Middleware¥ThrottleRequests::class,

        /**
        * カスタム
        */

        //共通のview変数
        'views' => ¥App¥Http¥Middleware¥Views::class, // <- new
        ];

        /**
        * アプリケーションのルートミドルウェアスタック
        *
        * These middleware may be assigned to groups or used individually.
        *
        * @var array
        */
        protected $routeMiddleware = [
        'auth' => ¥App¥Http¥Middleware¥Authenticate::class,
        'auth.basic' => ¥Illuminate¥Auth¥Middleware¥AuthenticateWithBasicAuth::class,
        'guest' => ¥App¥Http¥Middleware¥RedirectIfAuthenticated::class,
        'throttle' => ¥Illuminate¥Routing¥Middleware¥ThrottleRequests::class,

        /**
        * カスタム
        */

        //共通のview変数
        'views' => ¥App¥Http¥Middleware¥Views::class, // <- new
        ];
        コントローラからミドルウェアを呼び出す

        ベースコントローラにて middleware(‘views’) を追加する。


        <?php

        namespace App¥Http¥Controllers;

        use Illuminate¥Foundation¥Bus¥DispatchesJobs;
        use Illuminate¥Routing¥Controller as BaseController;
        use Illuminate¥Foundation¥Validation¥ValidatesRequests;
        use Illuminate¥Foundation¥Auth¥Access¥AuthorizesRequests;

        class Controller extends BaseController
        {
        use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

        public function __construct()
        {
        $this->middleware('auth');

        $this->middleware('views'); //<- new
        }
        }

        <?php

        namespace App¥Http¥Controllers;

        use Illuminate¥Foundation¥Bus¥DispatchesJobs;
        use Illuminate¥Routing¥Controller as BaseController;
        use Illuminate¥Foundation¥Validation¥ValidatesRequests;
        use Illuminate¥Foundation¥Auth¥Access¥AuthorizesRequests;

        class Controller extends BaseController
        {
        use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

        public function __construct()
        {
        $this->middleware('auth');

        $this->middleware('views'); //<- new
        }
        }
        これでviewの中で {{$username}} が使える。



        ただ、

        この例だとユーザ名しか渡してないし、viewで {{¥Auth::user()->name}} とすれば解決するのであんまり恩恵がない…

        動的に変更する必要がある共通項目とかなら真価を発揮できる。

        パッと思いつくのはAPIコント


        http://tk2-207-13211.vs.sakura.ne.jp/2016/04/815/


        テスト
        削除OK
        削除NG
        存在チェックng
        存在チェックok
        UNIQOK
        他リンクOK
        search
        ソースみて各パターンをテストする
        grep input blade.common
        grep radio blade.common
        grep select blade.common
        Event_Controller_test.php


        // create
        // init
        // update
        // edit
        // destory
        category:Laravel | by:ittoocomments(0)trackbacks(0) | -

        RWD-table sample javascript

        2016.11.10 Thursday 23:55
        0
          <html>
          <head>
          <meta charset="utf-8" />

          <title>Responsive tables</title>
          <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, minimal-ui">
          <meta name="format-detection" content="telephone=no">
          <meta name="description" content="An awesome solution for responsive tables with complex data.">

          <!-- Font Awesome -->
          <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">

          <!-- Latest compiled and minified Bootstrap CSS -->
          <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
          <link rel="stylesheet" href="rwd-table.css">

          <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
          <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
          <script type="text/javascript" src="http://localhost/testjs/examples/rwd-table.js"></script>

          </head>

          <body>


          <!--&#91;if lt IE 7 &#93;> <html lang="en" class="no-js lt-ie10 lt-ie9 lt-ie8 lt-ie7"> <!&#91;endif&#93;-->
          <!--&#91;if IE 7 &#93;> <html lang="en" class="no-js lt-ie10 lt-ie9 lt-ie8"> <!&#91;endif&#93;-->
          <!--&#91;if IE 8 &#93;> <html lang="en" class="no-js lt-ie10 lt-ie9"> <!&#91;endif&#93;-->
          <!--&#91;if IE 9 &#93;> <html lang="en" class="no-js lt-ie10"> <!&#91;endif&#93;-->
          <!--&#91;if (gt IE 9)|!(IE)&#93;><!--> <html lang="en" class="no-js"> <!--<!&#91;endif&#93;-->


          <h2>Responsive Table with RWD-Table-Patterns</h2>

          <div class="container">
          <div class="row">
          <div class="col-xs-12">

          <div class="table-responsive" data-pattern="priority-columns">
          <table class="table table-small-font table-bordered table-striped">
          <thead>
          <tr>
          <th>Country</th>
          <th data-priority="1">Languages</th>
          <th data-priority="2">Population</th>
          <th data-priority="3">Median Age</th>
          <th data-priority="4">Area (Km)</th>
          </tr>
          </thead>
          <tbody>
          <tr>
          <td>Argentina</td>
          <td>Spanish (official), English, Italian, German, French</td>
          <td>41,803,125</td>
          <td>31.3</td>
          <td>2,780,387</td>
          </tr>
          <tr>
          <td>Australia</td>
          <td>English 79%, native and other languages</td>
          <td>23,630,169</td>
          <td>37.3</td>
          <td>7,739,983</td>
          </tr>
          <tr>
          <td>Greece</td>
          <td>Greek 99% (official), English, French</td>
          <td>11,128,404</td>
          <td>43.2</td>
          <td>131,956</td>
          </tr>
          <tr>
          <td>Luxembourg</td>
          <td>Luxermbourgish (national) French, German (both administrative)</td>
          <td>536,761</td>
          <td>39.1</td>
          <td>2,586</td>
          </tr>
          <tr>
          <td>Russia</td>
          <td>Russian, others</td>
          <td>142,467,651</td>
          <td>38.4</td>
          <td>17,076,310</td>
          </tr>
          <tr>
          <td>Sweden</td>
          <td>Swedish, small Sami- and Finnish-speaking minorities</td>
          <td>9,631,261</td>
          <td>41.1</td>
          <td>449,954</td>
          </tr>
          </tbody>
          </table>
          </div><!--end of .table-responsive-->
          </div>
          </div>
          </div>
          </body>
          </html>
          ★★★★★
          <html>
          <head>
          <meta charset="utf-8" />

          <title>Responsive tables</title>
          <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, minimal-ui">
          <meta name="format-detection" content="telephone=no">
          <meta name="description" content="An awesome solution for responsive tables with complex data.">

          <!-- Font Awesome -->
          <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">

          <!-- Latest compiled and minified Bootstrap CSS -->
          <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
          <link rel="stylesheet" href="css/rwd-table.min.css">

          <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
          <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
          <script type="text/javascript" src="js/rwd-table.js"></script>

          </head>

          <body>

          <div class="table-responsive" data-pattern="priority-columns">
          <table class="table table-small-font table-bordered table-striped">
          <thead>
          <tr>
          <th>Company</th>
          <th data-priority="1">Last Trade</th>
          <th data-priority="3">Trade Time</th>
          <th data-priority="1">Change</th>
          <th data-priority="3">Prev Close</th>
          <th data-priority="3">Open</th>
          <th data-priority="6">Bid</th>
          <th data-priority="6">Ask</th>
          <th data-priority="6">1y Target Est</th>
          <th data-priority="6">Lorem</th>
          <th data-priority="6">Ipsum</th>
          </tr>
          </thead>
          <tbody>
          <tr>
          <th>GOOG <span class="co-name">Google Inc.</span></th>
          <td>597.74</td>
          <td>12:12PM</td>
          <td>14.81 (2.54%)</td>
          <td>582.93</td>
          <td>597.95</td>
          <td>597.73 x 100</td>
          <td>597.91 x 300</td>
          <td>731.10</td>
          <td colspan="2">Spanning cell</td>
          </tr>
          ...
          </tbody>
          </table>
          </div>

          <script>
          $(function() {
          $('#bs-deps').on('hide.bs.collapse show.bs.collapse', function () {
          $('#bs-deps-toggle').children('span').toggleClass('fa-chevron-down').toggleClass('fa-chevron-up');
          })
          });
          </script>
          </body>
          </html>
          category:javascript | by:ittoocomments(0)trackbacks(0) | -

          phpunit laravel

          2016.11.06 Sunday 17:23
          0
            http://www.techigniter.in/blogs/tutorials/query-logging-in-laravel-5/

            ・requestの形を統一する
            Mockery;
            https://medium.com/laravel-4/laravel-4-controller-testing-48414f4782d0#.qreur0n73
            ・repositoriテスト
            http://www.developer.com/services/testing-controllers-in-laravel-with-the-service-container.html
            Mockery::
            クラス内でnewしないようにする
            http://tech.aainc.co.jp/archives/3918
            https://readouble.com/laravel/5.1/ja/testing.html
            ----------


            namespace Formativ;

            use Illuminate¥Http¥Request;
            use Str;

            class PostRepository implements PostRepositoryInterface
            {
            public function __construct(Request $request)
            {
            $this->request = $request;
            }

            public function insert()
            {
            $data = [
            "title" => $this->request->get("title"),
            "subtitle" => $this->request->get("subtitle"),
            "body" => $this->request->get("body"),
            "author_id" => $this->request->get("author"),
            "slug" => Str::slug($this->request->get("title"))
            ];

            --------------
            public function testNewUserRegistration()
            {
            $this->visit('/register')
            ->type('Taylor', 'name')
            ->check('terms')
            ->press('Register')
            ->seePageIs('/dashboard');
            }


            メソッド 説明
            $this->type($text, $elementName) 指定したフィールドに「タイプ」します。
            $this->select($value, $elementName) ラジオボタンかドロップダウンフィールドを「選択」します。
            $this->check($elementName) チェックボックスフィールドを「チェック」します。
            $this->attach($pathToFile, $elementName) フォームにファイルを「添付」します。
            $this->press($buttonTextOrElementName) 指定したテキストか名前のボタンを「押し」ます。


            seeJsonメソッドは渡された配列をJSONに変換します。次にそのJSONが、JSONレスポンス全体のいずれかに現れるかを確認します。ですから、他のプロパティーがJSONレスポンスに含まれていたとしても、指定した部分が存在する限り、テストはパスします。

            JSONと一致するか確実に検証
            指定した配列がアプリケーションから返されるJSONと完全に一致するかを確認したい場合は、seeJsonEqualsメソッドを使用してください。


            class ExampleTest extends TestCase
            {
            /**
            * 基本的な機能テストの例
            *
            * @return void
            */
            public function testBasicExample()
            {
            $this->post('/user', ['name' => 'Sally'])
            ->seeJsonEquals([
            'created' => true,
            ]);
            }
            }

            カスタムHTTPリクエスト
            アプリケーションに対してカスタムHTTPリクエストを作成し、
            完全なIlluminate¥Http¥Responseオブジェクトを取得したい場合は、callメソッドを使ってください。

            public function testApplication()
            {
            $response = $this->call('GET', '/');

            $this->assertEquals(200, $response->status());
            }


            laravel input と request の違い

            フォームから一つの値を取得するにはInput::get()メソッドを使用します。



            Blade操作|データ表示
            {{ }}文は、XSS対策としてエスケープしてくれます。
            1
            {{ $name }}
            {!! !!}文は、エスケープしません。

            1
            {!! $name !!}



            CSRF対策
            csrf_field関数を使うと、CSRF対策用のトークン値を持つフィールドを生成してくれます。

            {{ csrf_field() }}

            「VerifyCsrfTokenミドルウェア」にて、「リクエストのトークン」と「セッションのトークン」が一致するかチェックしてくれます。


            configヘルパー関数でconfigデータを取得できます。
            $value = config('app.timezone');
            // デフォルト値指定
            $value = config('app.timezone', $default);
            http://www.dn-web64.com/archives/web/laravel-cheat/
            http://qiita.com/k-okada/items/c92a3f3594d751d42740

            validate
            in:foo,bar,... ★これ 存在チェックこれでいいんじゃね?
            exists:table,column ★これつかえるんんじゃね?しかし複数キーだしな・・・
            required_if:他のフィールド,値,...★ アクションTBLの スクリプト メール
            引数で指定された他のフィールドフィールドが、値のどれかを持っている場合に、このフィールドが入力されていることをバリデートします。


            required_if:state:0 ★スクリプト実行が選択されているときに必須とする
            $rules = [
            'name' => 'required|max:40',
            'gender' => 'required|in:male,female',
            'age' => 'digits_between:0,150',
            'use_discount' => 'boolean',
            'coupon' => 'required_if:use_discount,1|regex:/^[0-9a-zA-Z]{20}$/',
            ];


            ・トレイリングスラッシュについて ★
            URLは基本的に/exampleか/example/のどちらかに統一するのが通常かと思いますが、
            Laravelは/なしの方に寄せるほうが断然楽です。開発が始まる前になくなるように根回ししましょう。





            ・laravel debugger は、
            .env で
            APP_DEBUG=false # 実際に公開するアプリケーションは必ずfalseを設定(true/false)
            にすれば、app.php をさわらなくても laravel debuggerオフになるよ

            ・HOME_URL の設定
            config/local/app.php で
            //if (App::environment('local'))
            をやろうとしたが、うまくいかなかったのであきらめた
            →現状の env_application.php の if(/var/www/html/production.php)
            で判断しよう! laravelにあわせようとしたができんかったね


            ・validate
            in:foo,bar,...
            lavavelバリデートで以下を設定
            'title' => 'required|in:"あああ","いいい","ううう"',
            すると、上3つ以外を入力すると以下のエラーになる
            選択されたtitleは正しくありません。
            selectboxに追加しよう

            radio selectbox はこれ」対応する
            ・Config::get('app.timezone') 設定

            http://cheats.jesse-obrien.ca/

            category:php | by:ittoocomments(0)trackbacks(0) | -

            laravel database.phpファイルが紛らわしい

            2016.11.06 Sunday 06:19
            0
              laravel database.phpファイルが紛らわしい

              config/database.php はデータベースに関する設定を行うファイルだが
              あくまでDB設定は .env ファイルで行う。
              database.phpには、デフォルト値が記してある。(.envに設定がない場合に参照する)
              よって、database.phpを変更すれば環境に反映されるわけではなく .envファイルを
              変更しないといけない

              mysql の接続情報の定義箇所に env(‘DB_HOST’, ‘localhost’) とあります。
              これが .env ファイルを参照している箇所です。
              第1引数で .env ファイル内に定義してあるKEY指定し、そのVALUE値を取得します。
              第2引数はデフォルト値で、.envファイルが無かったり、KEYが設定されていない時は
              デフォルト値を使います。
              category:Laravel | by:ittoocomments(0)trackbacks(0) | -

              ad
              Calender
                12345
              6789101112
              13141516171819
              20212223242526
              27282930   
              << November 2016 >>
              Selected entry
              PR
              Category
              Archives
              Recommend
              Link
              Profile
              Search
              Others
              Mobile
              qrcode
              Powered
              無料ブログ作成サービス JUGEM