Php/laravel/laravel5/helloworld
提供: 初心者エンジニアの簡易メモ
それぞれ 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>
