[Laravel] 從routes.php帶參數至view (take parameters to view from routes.php)

繁體中文:

1、開啟app/routes.php,在/網址中,帶一個參數$name至hello.php(或hello.blade.php)中

Route::get('/', function()
{
  $name = "Carlos";
  return View::make('hello')->with("name", $name);
});

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

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

3、如果是使用blade template,則是開啟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 take a parameter to app/views/hello.php(or hello.blade.php):

Route::get('/', function()
{
  $name = "Carlos";
  return View::make('hello')->with("name", $name);
});

2、Open app/views/hello.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>

3. If use blade template, the open file: 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>