我使用make:auth命令进行身份验证。但当我打开" / home" url,它给了我那个错误。我不知道那是什么,我该如何解决这个问题。
完全错误:尝试获取非对象的属性(查看:/home/vagrant/www/blog/resources/views/front/pages/single.blade.php)
(我使用single.blade来显示我的帖子)
路线:
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
// also here is my single route
Route::get('/{slug}', 'BlogController@getSingle')->name('post_slug');
Single.blade.php
@extends('front.master')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="blog-post">
<h2 class="blog-post-title">{{$post->title}}</h2>
<p class="blog-post-meta">{{$post->created_at}} </p>
<hr/>
<div class="blog-main">
{{$post->body}}
</div>
</div>
</div>
</div>
@endsection
BlogController - getSingle
public function getSingle($slug){
$post = Post::where('slug', $slug)->first();
return view('front.pages.single')->with('post', $post);
}
Front.master刀片文件(简单的bootstrap示例)
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<title>Laravel 5 Blog Example</title>
<!-- Bootstrap core CSS -->
<link href="{{asset('/css/bootstrap.min.css')}}" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="{{asset('/css/blog.css')}}" rel="stylesheet">
</head>
<body>
<div class="blog-masthead">
<div class="container">
<nav class="nav">
<a class="{{Request::is('/') ? "nav-link active" : "nav-link"}}" href="{{route('home')}}">Anasayfa</a>
<a class="{{Request::is('about') ? "nav-link active" : "nav-link"}}" href="{{route('about')}}">Aboust Us</a>
<a class="{{Request::is('contact') ? "nav-link active" : "nav-link"}}" href="{{route('contact')}}">Contact Us</a>
<a class="{{Request::is('home') ? "nav-link active" : "nav-link"}}" href="{{route('home')}}">Home</a>
<a class="nav-link" href="{{url('admin/panel')}}">Admin</a>
</nav>
</div>
</div>
@yield('content')
<footer class="blog-footer">
<p>
Yeni Bir Blog Denemesi | Laravel 5.5 <br>
<a href="#">Yukarı çık</a>
</p>
</footer>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="../../../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="../../../../assets/js/vendor/popper.min.js"></script>
<script src="../../../../dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../../../assets/js/ie10-viewport-bug-workaround.js"></script>
</html>
我在哪里弄错了?
答案 0 :(得分:2)
Route::get('/home', 'HomeController@index')->name('home');
在路线档案中使用以下
Route::get('/', 'HomeController@index')->name('home');
<a class="{{Request::is('/') ? "nav-link active" : "nav-link"}}" href="{!! route('home') !!}">Anasayfa</a>
答案 1 :(得分:0)
尝试在Single.blade.php
中使用此功能:
@extends('front.master')
@section('content')
@if(count($post) > 0)
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="blog-post">
<h2 class="blog-post-title">{{$post->title}}</h2>
<p class="blog-post-meta">{{$post->created_at}} </p>
<hr/>
<div class="blog-main">
{{$post->body}}
</div>
</div>
</div>
</div>
</div>
@else
<h3>No post yet.</h3>
@endif
@endsection