ユーザ用ツール

サイト用ツール


サイドバー

このページの翻訳:



最近の更新



Tag Cloud

11_php:02_framework:01_laravel:28_laravel_voyger_front-end

文書の過去の版を表示しています。


28 Laravel Voyager フロントページ用意

Post

一覧ページ

1.ルーティング

routes/web.php

Route::get('/foo', function () {
    $posts = App\Post::all();
    return view('home', compact('posts'));
});

2.コントローラ

コントローラ作成

php artisan make:model Post

下記ができる

app/Post.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    //
}

3.Viewを作成

resources/views/home.blade.php

<!DOCTYPE html>
<html>
<head>
	<title>Homepage</title>
	<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

	<div class="container">
		<br><br>
		<div class="row">
		@foreach($posts as $post)
			<div class="col-md-3">
				<a href="/post/{{ $post->slug }}">
					<img src="{{ Voyager::image( $post->image ) }}" style="width:100%">
					<span>{{ $post->title }}</span>
				</a>
			</div>
		@endforeach
		</div>
	</div>

</body>
</html>

4.ページ完成

一覧のページが完成

シングルページ

1.ルーティング

routes/web.php

Route::get('post/{slug}', function($slug){
	$post = App\Post::where('slug', '=', $slug)->firstOrFail();
	return view('post', compact('post'));
});

2.View

resources/views/post.blade.php

<!DOCTYPE html>
<html>
<head>
	<title>{{ $post->title }}</title>
	<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

	<div class="container">
		<div class="row">
			<div class="col-md-8 col-md-offset-2">

				<h1>{{ $post->title }}</h1>
				<img src="{{ Voyager::image( $post->image ) }}" style="width:100%">
				<p>{!! $post->body !!}</p>

			</div>
		</div>
	</div>

</body>
</html>
11_php/02_framework/01_laravel/28_laravel_voyger_front-end.1612341043.txt.gz · 最終更新: 2021/02/03 17:30 by matsui