LoginSignup
1
2

More than 5 years have passed since last update.

Laravelのルーティング

Posted at

それぞれのアプリケーション同士をつなげるためのルーティングをしていきます。

Laravelでのルーティングは アプリ名>appフォルダ以下にあるroutes.phpで主に行っていきます。

routes.phpを開いてみると、
<?php
/*コメント*/
Route::get('/', function()
{
return View::make('hello');
});

てな感じです。

これはget()でルート('/')のアドレスが呼ばれたときにapp>viewsフォルダ内のhello.phpをよびだします。

例えば、app>views以下にtest.phpを作り、
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

とHello Worldを表示させます。

そしてroutes.phpは
Route::get('/', function()
{
return View::make('test');
});

となります。.phpはいりません。
保存してプレビュー表示してみると

Screenshot (72).png

こうなります。

getのアドレス名(ルートのときは/)は任意で決めることができ、
アドレスshowでhello.phpを開きたいときは
routes.php
<?php
Route::get('show', function()
{
return View::make('hello');
});

呼ぶ側でたとえば
<a href = "show" >こんにちは</a>

このリンクがクリックされたとき、routes.phpを介してhello.phpが呼ばれます。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2