「Php/laravel/laravel5/helloworld」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「それぞれttp://localhost/helloでアクセスするとhelloworldと表示される ==ルーターでhelloworld== vi app/Http/routes.php Route::get('/hello', function...」) |
|||
| (同じ利用者による、間の4版が非表示) | |||
| 行1: | 行1: | ||
| − | + | それぞれ ttp://localhost/hello でアクセスするとhelloworldと表示される | |
| + | |||
| + | ==ルーターの場所== | ||
| + | laravel5.2の場合 | ||
| + | app/Http/routes.php | ||
| + | laravel5.4の場合 | ||
| + | routes/web.php | ||
==ルーターでhelloworld== | ==ルーターでhelloworld== | ||
| − | vi | + | vi routes.php |
Route::get('/hello', function () { | Route::get('/hello', function () { | ||
return 'helloworld'; | return 'helloworld'; | ||
| 行8: | 行14: | ||
==コントローラーでhelloworld== | ==コントローラーでhelloworld== | ||
| − | vi | + | vi routes.php |
Route::get('/hello', 'HelloController@index'); | Route::get('/hello', 'HelloController@index'); | ||
| 行30: | 行36: | ||
public function index() | public function index() | ||
{ | { | ||
| − | + | $data = []; | |
| + | $data["title"] = "hello"; | ||
| + | return view('hello.index', $data); | ||
} | } | ||
} | } | ||
2018年1月19日 (金) 11:14時点における最新版
それぞれ ttp://localhost/hello でアクセスするとhelloworldと表示される
ルーターの場所
laravel5.2の場合
app/Http/routes.php
laravel5.4の場合
routes/web.php
ルーターでhelloworld
vi routes.php
Route::get('/hello', function () {
return 'helloworld';
});
コントローラーでhelloworld
vi 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>
