yusukesasaki-com / Mitarashi

MIT License
0 stars 0 forks source link

Laravelのインストール・設定 #2

Closed yusukesasaki-com closed 7 years ago

yusukesasaki-com commented 8 years ago

公式サイト

https://laravel.com

日本語サイト

http://laravel.jp https://laravel10.wordpress.com http://www.larajapan.com

yusukesasaki-com commented 8 years ago

インストール

Composerをインストール

curl -sS https://getcomposer.org/installer | php

「パスを通す」

mv composer.phar /usr/local/bin/composer

cms ディレクトリ(自動で作られる)に Laravelをインストール

composer create-project --prefer-dist laravel/laravel cms

かなり時間がかかるがおとなしく待つ。

ビルトインサーバーを立ち上げてブラウザで表示

cd cms
php artisan serve --host xxx.xxx.xx.xx --port xxxx 

xxx.xxx.xx.xx:xxxx にアクセス

初期画面表示成功

2016-01-21 2 36 00

yusukesasaki-com commented 8 years ago

初期設定

データベース

/cms/.env の下記部分に記述 .env はバージョン管理に含まれない(.gitignoreにより)

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

タイムゾーン・言語

/cms/config/app.php

'timezone' => 'Asia/Tokyo',
'locale' => 'ja',

バリデーションを日本語化

https://gist.github.com/syokunin/b37725686b5baf09255b

/cms/resources/lang/ja/validation.php に格納

yusukesasaki-com commented 8 years ago

ヘルパーのインストール

composer require laravelcollective/html

/cms/config/app.php

return [
    // サービス・プロバイダーの登録
    'providers' => [

        // ...

        Collective\Html\HtmlServiceProvider::class,  // 追加
    ],

    // ファサードの登録
    'aliases' => [

        // ...

        'Form' => Collective\Html\FormFacade::class,  // 追加
        'Html' => Collective\Html\HtmlFacade::class,  // 追加
    ],
];
yusukesasaki-com commented 8 years ago

public 内のファイルを外に出して http://hogehoge/cms/ を管理画面のルートにする

cms/public/index.php -> cms/index.php

// ...

require __DIR__.'/bootstrap/autoload.php'; // 変更

// ...

$app = require_once __DIR__.'/bootstrap/app.php'; // 変更

$app->bind('path.public', function() { // 追加
    return __DIR__;
});

// ...

参考

http://www.larajapan.com/2016/02/27/public%E3%81%AE%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%82%92%E7%A7%BB%E5%8B%95%E3%81%99%E3%82%8B/

メモ

※ビルトインサーバーではhtaccessのmod_rewriteが無効になってhttp://xxx.xxx.xx.xx:xxxx/cms にアクセスするとエラーになる(http://xxx.xxx.xx.xx:xxxx/cms/ にリダイレクトされない)ため、「ルータスクリプト」で代行する。

$ php -S xxx.xxx.xx.xx:xxxx -t ./ ./index.php

index.php (http://xxx.xxx.xx.xx:xxxx/cms にアクセスしたら http://xxx.xxx.xx.xx:xxxx/cms/ にリダイレクト)

<?php

preg_match("/\/cms$/", $_SERVER["REQUEST_URI"], $dir);

if (!empty($dir)) {
  if ($dir[0] == '/cms') {
    header('Location: /cms/');
    exit;
  } else {
    return false;
  }
} else {
  return false;
}

参考

http://blog.mach3.jp/2014/06/13/php54-builtin-server.html

yusukesasaki-com commented 8 years ago

ログイン機能を実装

参考

ログイン https://laravel10.wordpress.com/2015/03/24/%E5%88%9D%E3%82%81%E3%81%A6%E3%81%AElaravel-5-28-%E8%AA%8D%E8%A8%BC/

ミドルウェア https://laravel10.wordpress.com/2015/03/26/%E5%88%9D%E3%82%81%E3%81%A6%E3%81%AElaravel-5-30-middleware/ http://blog.fagai.net/2015/04/10/laravel5-middleware/

マルチ認証(今後の参考に) http://www.larajapan.com/2016/01/18/%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E8%AA%8D%E8%A8%BC%EF%BC%88%EF%BC%91%EF%BC%90%EF%BC%89laravel-5-2-%E3%83%9E%E3%83%AB%E3%83%81%E8%AA%8D%E8%A8%BC/ http://tech.pjin.jp/blog/2016/02/17/php-framework-laravel-primer-4/

yusukesasaki-com commented 8 years ago

DB関連

migration フィールドの型

https://laravel.com/docs/5.2/migrations

yusukesasaki-com commented 8 years ago

WYSIWYG「TinyMCE」を設置

https://github.com/ktquez/laravel-tinymce [LICENSE MIT]

composer require ktquez/laravel-tinymce 

config/app.phpに下記を追加

・・・
'providers' => [
・・・
    Ktquez\Tinymce\TinymceServiceProvider::class,
・・・
php artisan vendor:publish --force

public内にvendorディレクトリが作成されるので、中身をルートのvendor内に移動 cms/public/vendor/js/* -> cms/vendor/js/*

artisanを実行するとエラーが発生するようになってしまっているので、cms/config/tinymce.php を編集

'cdn' => url('vendor/js/tinymce/tinymce.min.js'),

'cdn' => app()->runningInConsole() ? null : url('vendor/js/tinymce/tinymce.min.js'),

に変更。

日本語化

TinyMCEの公式サイトから日本語データをダウンロード

https://www.tinymce.com/download/language-packages/

ダウンロードしたja.jsを cms/vendor/js/tinymce/langs/ に追加

cms/confit/config/tinymce.php の "language" => 'en',"language" => 'ja', に変更。

日本語化完了

画像アップロード機能追加 プラグイン「justboil」 を追加

下記からダウンロード -> zipを解凍 -> cms/vendor/js/tinymce/plugins/jbimages/ ディレクトリを作成して、解凍した中身を全てアップロード

https://github.com/vikdiesel/justboil.me

cms/vendor/js/tinymce/plugins/jbimages/config.php の $config['img_path'] = '/images';$config['img_path'] = '/uploads'; に変更して cms/ の上の階層に uploads ディレクトリを作成

cms/confit/config/tinymce.php を変更

"plugins" =>"toolbar" => の中に jbimages を追加 "relative_urls" => false, を追記

'default' => [
  "selector" => ".tinymce",
  "language" => 'ja',
  "theme" => "modern",
  "skin" => "lightgray",
  "plugins" => [
         "advlist autolink link image jbimages lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor"
  ],
  "toolbar" => "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages | print preview media fullpage | forecolor backcolor emoticons",
  "relative_urls" => false,
],