2017年8月16日水曜日

Laravelにおけるviewに変数を渡す方法

viewのwelcomeに変数$nameを渡すには、以下の方法がある

1)
Route::get('/', function () {
    return view('welcome', ['name' => 'World',
    ]);
});

2)
Route::get('/', function () {
    return view('welcome')->with('name', 'World');
});

3)
Route::get('/', function () {
 $name = 'World';
    $age = 42;

    return view('welcome', ['name' => $name,
                                           'age' => $age,
    ]);
    //same with, return view('welcome',  compact('name', 'age'));
});

Route::get('/', function () {
    $tasks = [
        'qwe',
        'asd',
        'zxc'
    ];

    return view('welcome', compact('tasks'));
});

shellの$()

tplList.txtに保存するfile listを対象にgrepしたい。

grep -i "href" $(cat tplList.txt)
$()の意味は``と同じ、実行結果をgrepに渡す

valetの使い方

Valet is a Laravel development environment for Mac minimalists. No Vagrant, no /etc/hosts file. 
Laravel Valet configures your Mac to always run Nginx in the background when your machine starts. 
Then, using DnsMasq, Valet proxies all requests on the *.dev domain to point to sites installed on your local machine.


インストールには
composer global require laravel/valet
valet install

valetが正しくインストールされているかどうかを確認するには、任意の.dev domianをpingしてみる
ping foo.dev

valetがサイトを探す時のpathを指定
mkdir lara
cd lara
valet park

larval new blog
blog.dev にアクセスすると、laravelの画面が出る

httpsを有効にする
valet secure blog

httpsを有効から無効にする
valet unsecure blog