「Php/laravel/laravel5/helloworld」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「それぞれttp://localhost/helloでアクセスするとhelloworldと表示される ==ルーターでhelloworld== vi app/Http/routes.php Route::get('/hello', function...」) |
(→ビューでhelloworld) |
||
| 行30: | 行30: | ||
public function index() | public function index() | ||
{ | { | ||
| − | + | $data = []; | |
| + | $data["title"] = "hello"; | ||
| + | return view('hello.index', $data); | ||
} | } | ||
} | } | ||
2016年8月5日 (金) 00:59時点における版
それぞれttp://localhost/helloでアクセスするとhelloworldと表示される
ルーターでhelloworld
vi app/Http/routes.php
Route::get('/hello', function () {
return 'helloworld';
});
コントローラーでhelloworld
vi app/Http/routes.php
Route::get('/hello', 'HelloController@index');
vi app/Http/Controllers/HelloController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class HelloController extends Controller
{
public function index()
{
return 'helloworld';
}
}
ビューでhelloworld
vi app/Http/Controllers/HelloController.php
class HelloController extends Controller
{
public function index()
{
$data = [];
$data["title"] = "hello";
return view('hello.index', $data);
}
}
vi resources/views/hello/index.blade.php
<h1>{{ $title }}</h1>
