@extends('layouts.master')
@section('content')
<!-- Page Header -->
<header class="masthead" style="background-image: url('{{asset('assets/img/home-bg.jpg')}}')">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="site-heading">
<h1>Laravel Blog</h1>
<span class="subheading">The php framework for web artisans</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
@foreach($posts as $post)
<div class="post-preview">
<a href="#">
<h2 class="post-title">
{{$post->title}}
</h2>
</a>
<p class="post-meta">Posted by
<a href="#">{{$post->user->name}}</a>
on {{$post->created_at}}</p>
</div>
<hr>
@endforeach
<!-- Pager -->
<div class="clearfix">
<a class="btn btn-primary float-right" href="#">Older Posts </a>
</div>
</div>
</div>
</div>
@endsection
控制器代码:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
class PublicController extends Controller
{
public function index(){
$posts= Post::all();
return view('welcome', compact( 'posts'));
}
public function singlePost($id){
return view('singlePost');
}
public function about(){
return view('about');
}
public function contact(){
return view('contact');
}
public function contactPost(){
}
}
我一直在修改我的代码超过24小时仍然无法弄清楚为什么帖子没有显示在我的主页上。路线还可以,他们正常工作只是在传递帖子时没有显示的信息,任何人都可以帮助