Last active
August 29, 2015 14:19
-
-
Save astrsk-hori/0f81662a94205a2345b8 to your computer and use it in GitHub Desktop.
laravel5を試してみる(メモ) ref: http://qiita.com/astrsk_hori/items/c3748c588164ab0ebd1b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer create-project laravel/laravel la5test --prefer-dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config/database.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources/views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources/views/home.blade.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources/views/tasks/index.blade.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan tinker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ php artisan route:list | |
+--------+--------------------------------+-------------------------------------------------------+--------------+------------------------------------------------------------+------------+ | |
| Domain | Method | URI | Name | Action | Middleware | | |
+--------+--------------------------------+-------------------------------------------------------+--------------+------------------------------------------------------------+------------+ | |
| | GET|HEAD | / | | App\Http\Controllers\WelcomeController@index | guest | | |
| | GET|HEAD | home | | App\Http\Controllers\HomeController@index | auth | | |
| | GET|HEAD | task | task.index | App\Http\Controllers\TaskController@index | | | |
| | GET|HEAD | task/create | task.create | App\Http\Controllers\TaskController@create | | | |
| | POST | task | task.store | App\Http\Controllers\TaskController@store | | | |
| | GET|HEAD | task/{task} | task.show | App\Http\Controllers\TaskController@show | | | |
| | GET|HEAD | task/{task}/edit | task.edit | App\Http\Controllers\TaskController@edit | | | |
| | PUT | task/{task} | task.update | App\Http\Controllers\TaskController@update | | | |
| | PATCH | task/{task} | | App\Http\Controllers\TaskController@update | | | |
| | DELETE | task/{task} | task.destroy | App\Http\Controllers\TaskController@destroy | | | |
| | GET|HEAD | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getRegister | guest | | |
| | POST | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@postRegister | guest | | |
| | GET|HEAD | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getLogin | guest | | |
| | POST | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@postLogin | guest | | |
| | GET|HEAD | auth/logout/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getLogout | | | |
| | GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing} | | App\Http\Controllers\Auth\AuthController@missingMethod | guest | | |
| | GET|HEAD | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@getEmail | guest | | |
| | POST | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@postEmail | guest | | |
| | GET|HEAD | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@getReset | guest | | |
| | POST | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@postReset | guest | | |
| | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing} | | App\Http\Controllers\Auth\PasswordController@missingMethod | guest | | |
+--------+--------------------------------+-------------------------------------------------------+--------------+------------------------------------------------------------+------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Http\Controllers; | |
use App\Http\Requests; | |
use App\Http\Controllers\Controller; | |
use App\Task; | |
use Illuminate\Http\Request; | |
class TaskController extends Controller { | |
protected $tasks; | |
public function __construct(Task $tasks) | |
{ | |
$this->tasks = $tasks; | |
} | |
/** | |
* Display a listing of the resource. | |
* | |
* @return Response | |
*/ | |
public function index() | |
{ | |
$tasks = $this->tasks->all(); | |
return view('tasks.index', ['tasks' => $tasks]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://localhost/task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan tinker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> $task = App::make('\App\Task'); | |
=> <App\Task #000000003956511c000000011e1b911e> {} | |
>>> $task->title = 'test title'; | |
=> "test title" | |
>>> $task->body = '本文です'; | |
=> "本文です" | |
>>> $task->save(); | |
=> true | |
>>> $task->all(); | |
=> <Illuminate\Database\Eloquent\Collection #0000000039565101000000011e1b911e> [ | |
<App\Task #00000000395651f1000000011e1b911e> { | |
id: 1, | |
title: "test title", | |
body: "本文です", | |
created_at: "2015-04-16 06:30:57", | |
updated_at: "2015-04-16 06:30:57" | |
} | |
] | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Http\Controllers; | |
use App\Http\Requests; | |
use App\Http\Controllers\Controller; | |
use App\Task; | |
use Illuminate\Http\Request; | |
class TaskController extends Controller { | |
protected $tasks; | |
public function __construct(Task $tasks) | |
{ | |
$this->tasks = $tasks; | |
} | |
/** | |
* Display a listing of the resource. | |
* | |
* @return Response | |
*/ | |
public function index() | |
{ | |
$tasks = $this->tasks->all(); | |
return view('tasks.index', ['tasks' => $tasks]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan migrate --env=testing | |
php artisan key:generate --env=testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use App\Task; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create database la5test default character set utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('app') | |
@section('content') | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-10 col-md-offset-1"> | |
<div class="panel panel-default"> | |
<div class="panel-heading">Task List</div> | |
<div class="panel-body"> | |
<ul class="list-group"> | |
@foreach ($tasks as $task) | |
<li class="list-group-item">{{$task->title}}</li> | |
@endforeach | |
</ul> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan migrate --env=testing | |
php artisan key:generate --env=testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DB_HOST=localhost | |
DB_DATABASE=la5test | |
DB_USERNAME=hoge | |
DB_PASSWORD=hogehoge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan make:model Task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan make:model models/Task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateTasksTable extends Migration { | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('tasks', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->string('title'); | |
$table->text('body'); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::drop('tasks'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> show tables; | |
+-------------------+ | |
| Tables_in_la5test | | |
+-------------------+ | |
| migrations | | |
| password_resets | | |
| tasks | | |
| users | | |
+-------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan make:controller TaskController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::resource('task', 'TaskController'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment