LoginSignup
1
0

More than 3 years have passed since last update.

がっつり開発するほどじゃないけどちょっとLaravelいじりたい時の環境構築

Last updated at Posted at 2020-03-13

Laravel使ってるところに放り込まれたので軽く予習するために環境を作ったメモ。

macOS Catalina v10.15.3
Homebrew v2.2.9

Composerインストール

▶︎ brew install composer
▶︎ composer -V
Composer version 1.9.3

PHPインストール

MacにプリインストールされているPHPを使ってると、このあとうまくいかなかったのでついでにPHPも入れる。
どのみち、公式Homesteadを使わないならPHP >= 7.2.5じゃないとだめって書いてあるのでアップデートの必要はあったっぽいが詳しくはわからない。

▶︎ brew search php
==> Formulae
brew-php-switcher      php-cs-fixer           phplint                phpstan
php                    php@7.2                phpmd                  phpunit
php-code-sniffer       php@7.3                phpmyadmin

brew install phpしたらv7.4.3が入った。

Laravelインストール

▶︎ composer require "laravel/installer"
▶︎ laravel new ディレクトリ名

もしくは

▶︎ composer create-project laravel/laravel ディレクトリ名

(どっちの方がいいとかあるのだろうか?)

バージョン確認

▶︎ php artisan -V
Laravel Framework 7.0.8

Hello World

コントローラー

▶︎ php artisan make:controller SampleController
Controller created successfully.
app/Http/Controllers/SampleController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SampleController extends Controller
{
    public function sampleFunction()
    {
        $hello = 'Hello';
        return view('sample', ['h' => $hello, 'w' => 'World']);
    }
}

ビュー

resources/views/sample.blade.php
<h1>{{ $h }} {{ $w }}</h1>

ルーティング

routes/web.php
<?php

use Illuminate\Support\Facades\Route;

Route::get('/','SampleController@sampleFunction');

ローカルサーバー起動

▶︎ php artisan serve
Laravel development server started: http://127.0.0.1:8000

HelloWorld

http://127.0.0.1:8000にアクセスするとこんな感じ。

TODO

  • Bladeテンプレート
  • artisanコマンド
  • データベース関連
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0