2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

laravelでHello World

Last updated at Posted at 2018-10-17

PHPで人気のlaravelを使ってみます。

##1.環境

php, composer, laravelのインストールは完了しているものとします。

  version
os windows10 64bit home 
php 7.2.10
Laravel 5.7.9

##2.Hello Worldの構築

###(1)プロジェクトを作成する。

composer create-project laravel/laravel helloworld

###(2)プロジェクトフォルダ「helloworld」に移動

cd helloworld

###(3)web.phpを編集

helloworld\routes\web.php
<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


Route::get('/', function () {
    return view('welcome');
});

Route::get('hello', 'HelloController@index');

###(4)Controllerを作成

cmd.prompt
php artisan make:controller Hello2Controller

###(5)Controllerを編集

helloworld\app\Http\Controllers\HelloController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HelloController extends Controller
{
    //
  public function index()
  {
    return view('hello');
  }
}

###(6)viewを作成

resources\views\hello.blade.php
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>My First Page</title>
</head>
<body>
  <h2>Hello World from blade!!</h2>
  <p>{{date("Y/m/d H:i:s")}}</p>
</body>
</html>

###(7)サーバを起動

cmd.prompt
php -S localhost:8000 -t public

###(8)動作確認

ブラウザで以下のURLにアクセスする。
http://localhost:8000/hello

image.png

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?