[Laravel] 從controller帶參數至view(take parameter to view file from controller)

繁體中文:

1、開啟app/routes.php並編輯:

// 指定使用app/controllers/PagesController.php並呼叫home function:
Route::get("/", "PagesController@home");

2、開啟app/controllers/PagesController.php並編輯:

<?php
class PagesController extends BaseController{
  public function home(){
    $name = "Carlos";
    return View::make('hello')->with("name", $name);
  }
}

3、開啟app/views/hello.blade.php並編輯:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Laravel PHP Framework</title>
</head>
<body>
  <h1>Hello, {{ $name }}</h1>
</body>
</html>

English Version:

1. Open app/routes.php and edit:

// Assign app/controllers/PagesController.php and call "home function":
Route::get("/", "PagesController@home");

2. Open app/controllers/PagesController.php and edit:

<?php
class PagesController extends BaseController{
  public function home(){
    $name = "Carlos";
    return View::make('hello')->with("name", $name);
  }
}

3. Open app/views/hello.blade.php and edit:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Laravel PHP Framework</title>
</head>
<body>
  <h1>Hello, {{ $name }}</h1>
</body>
</html>