Blockquote
我正在laravel中开发一个网站,但遇到错误(尝试获取非对象的属性)可以帮助我 我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use app\Http\Requests;
use Session;
use Illuminate\Support\Facades\Redirect;
Session_start();
class HomeController extends Controller
{
public function index()
{
return view('page.home');
}
public function blog_details($id)
{
$blog_detail=DB::table('blog')
->join('users','blog.author','=','users.id')
->select('blog.*')
->where('blog.id',$id)
->first();
$manage_detail=view('page.blog_details')
->with('blog_detail',$blog_detail);
return view('layout')
->with('page.blog_details',$manage_detail);
}
public function event_detail($id)
{
$event_detail=DB::table('events')
->join('users','events.author','=','users.id')
->where('events.id',$id)
->first();
$manage_details=view('page.event_detail')
->with('event_detail',$event_detail);
return view('layout')
->with('page.event_detail',$manage_details);
}
}
下面的代码是我的刀片Blog_details.blade.php
@extends('layout')
@section('home')
<div class="hero-wrap" style="background-image: url('{{asset($blog_detail->main_photo)}}');" data-stellar-background-ratio="0.5">
<div class="overlay"></div>
<div class="container">
<div class="row no-gutters slider-text align-items-center justify-content-center" data-scrollax-parent="true">
<div class="col-md-7 ftco-animate text-center" data-scrollax=" properties: { translateY: '70%' }">
<h1 class="mb-3 bread" data-scrollax="properties: { translateY: '30%', opacity: 1.6 }">{{($blog_detail->title or 'No last product')}}</h1>
</div>
</div>
</div>
</div>
<section class="ftco-section ftco-degree-bg">
<div class="container">
<div class="row">
<div class="col-md-8 ftco-animate">
<h2 class="mb-3">{{($blog_detail->short_description)}}</h2>
{{($blog_detail->content)}}
<div class="tag-widget post-tag-container mb-5 mt-5">
<div class="tagcloud">
<a href="https:/twitter.com/{{($blog_detail->hash_tag)}}" class="tag-cloud-link">{{($blog_detail->hash_tag)}}</a>
</div>
</div>
<div class="about-author d-flex p-5 bg-light">
<div class="bio align-self-md-center mr-5">
<img src="{{asset($blog_detail->photo)}}" alt="Image placeholder" class="img-fluid mb-4" style="width: 150px;height: auto;">
</div>
<div class="desc align-self-md-center">
<h3>{{($blog_detail->firstname)}} {{($blog_detail->lastname)}}</h3>
<p>{{($blog_detailget_blog->quote)}}</p>
</div>
</div>
</div><!-- .col-md-8 -->
<div class="col-md-4 sidebar ftco-animate">
<div class="sidebar-box">
<form action="#" class="search-form">
<div class="form-group">
<span class="icon fa fa-search"></span>
<input type="text" class="form-control" placeholder="Type a keyword and hit enter">
</div>
</form>
</div>
<div class="sidebar-box ftco-animate">
<h3>Recent Blog</h3>
<?php
$all=DB::table('blog')
->join('users','blog.author','=','users.id')
->OrderBy('blog.id','DESC')
->limit(2,4)
->get();
?>
@foreach( $all as $all )
<div class="block-21 mb-4 d-flex">
<a class="blog-img mr-4" style="background-image: url({{asset($all->main_photo)}});"></a>
<div class="text">
<h3 class="heading"><a href="#">{{($all->short_description)}}</a></h3>
<div class="meta">
<div><a href="#"><span class="icon-calendar"></span> July 12, 2018</a></div>
<div><a href="#"><span class="icon-person"></span> {{($all->firstname)}}</a></div>
<div><a href="#"><span class="icon-chat"></span> 19</a></div>
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>
</section>
@endsection