6
6

More than 5 years have passed since last update.

Laravelを90分だけさわってみる。

Last updated at Posted at 2014-03-14

Laravel Quickstart

Installation

$ laravel new blog

You have arrived.が表示された。

Routing

app/routes.php
Route::get('users', function()
{
    return 'Users!';
});

Users!が表示された。

app/views/layout.blade.php
<html>
    <body>
        <h1>Laravel Quickstart</h1>

        @yield('content')
    </body>
</html>
app/views/users.blade.php
@extends('layout')

@section('content')
    Users!
@stop
app/routes.php
Route::get('users', function()
{
    return View::make('users');
});

Laravel Quickstart
Users!
が表示された。

Creating A Migration

app/config/database.php
        'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'laravel_test',
            'username'  => '',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),

$ php artisan migrate:make create_users_table

app/database/migrations/2014_03_14_071230_create_users_table.php
    public function up()
    {
        Schema::create('users', function($table)
        {
            $table->increments('id');
            $table->string('email')->unique();
            $table->string('name');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::drop('users');
    }

$ php artisan migrate

テーブルできた。すげぇ。
表示テストのために手動で1行入れとく。

Eloquent ORM

app/routes.php
Route::get('users', function()
{
    $users = User::all();

    return View::make('users')->with('users', $users);
});

Displaying Data

app/views/users.blade.php
@extends('layout')

@section('content')
    @foreach($users as $user)
        <p>{{ $user->name }}</p>
    @endforeach
@stop

表示されたよ。。。

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