「Php/laravel/laravel5/helloworld」の版間の差分
提供: 初心者エンジニアの簡易メモ
| 行1: | 行1: | ||
| − | + | それぞれ ttp://localhost/hello でアクセスするとhelloworldと表示される | |
==ルーターの場所== | ==ルーターの場所== | ||
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>
