「Php/laravel/laravel5/helloworld」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→ビューでhelloworld) |
(→コントローラーでhelloworld) |
||
| 行8: | 行8: | ||
==コントローラーでhelloworld== | ==コントローラーでhelloworld== | ||
| − | vi app/Http/routes.php | + | vi app/Http/routes.php or routes/web.php |
Route::get('/hello', 'HelloController@index'); | Route::get('/hello', 'HelloController@index'); | ||
2018年1月18日 (木) 11:31時点における版
それぞれttp://localhost/helloでアクセスするとhelloworldと表示される
ルーターでhelloworld
vi app/Http/routes.php
Route::get('/hello', function () {
return 'helloworld';
});
コントローラーでhelloworld
vi app/Http/routes.php or routes/web.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>
