close
/*檔案:routes/web.php*/
Route::get('/contact','PostController@contact');
/*檔案:app/http/controllers/PostController.php*/
public function contact(){
return view('contact');
}
<!-- 檔案:resoures/views/contact.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
哈囉你好
</body>
</html>
瀏覽器網址列:localhost/contact
出現文字:哈囉你好
/*檔案:routes/web.php*/
Route::get('/post/{id}','PostController@show_post');
/*檔案:app/http/controllers/PostController.php*/
public function show_post($id){
return view('post')->with('id',$id);
}
<!-- 檔案:resoures/views/post.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
這篇文章編號是{{$id}}
</body>
</html>
瀏覽器網址列:localhost/post/25
出現文字:這篇文章編號是25
/*檔案:routes/web.php*/
Route::get('/post/{id}/{name}/{content}','PostController@show_post');
/*檔案:app/http/controllers/PostController.php*/
public function show_post($id,$name,$content){
return view('post',compact('id','name','content'));
}
<!-- 檔案:resoures/views/post.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
這篇文章編號是{{$id}},標題是{{$name}},內容是{{$content}}
</body>
</html>
瀏覽器網址列:localhost/post/25/56不能亡/我難過
出現文字:這篇文章編號是25,標題是56不能亡,內容是我難過
<!-- 檔案:resources/view/layouts/app.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="container">
@yield('content')
</div>
@yield('footer')
</body>
</html>
<!-- 檔案:resoures/views/post.blade.php -->
@extends('layouts.app')
@section('content')
<h1>Post Page {{$id}} {{$name}} {{$password}}</h1>
@stop
把上例用layouts/app切開,建立模板
/*檔案:routes/web.php*/
Route::get('/contact','PostController@contact');
/*檔案:app/http/controllers/PostController.php*/
public function contact(){
$people=['edwin','jose','james','peter','maria'];
return view('contact',compact('people'));
}
<!-- 檔案:resources/view/layouts/app.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="container">
@yield('content')
</div>
@yield('footer')
</body>
</html>
/*檔案:resoures/views/post.blade.php */
@extends('layouts.app')
@section('content')
<h1>Contact Page</h1>
<ul>
@if(count($people))
@foreach($people as $person)
<li>{{$person}}</li>
@endforeach
@endif
</ul>
@stop
@section('footer')
@stop
瀏覽器網址列:localhost/contact
顯示:
Contact Page
- edwin
- jose
- james
- peter
- maria
全站熱搜