我想在与收入和支出表都连接的IncomeExpense表中显示收入名称和支出名称,并且这两个表都具有name列,可从中获取信息并将其显示在IncomeExpense表中。我已经正确连接了所有表,但是收到错误消息:“试图获取非对象的属性'title' 查看:
@extends('layouts.app')
@section('content')
<br>
<br>
<div class="card bg-muted">
<h1>{{$incexp->IncomeExpense}}</h1>
<small>{{$incexp->created_at}}</small>
<small> {{$incexp->income->title }}</small>**--get issue here**
<small>{{$incexp->SumOfMoney}}</small>
<small> {{$incexp->Comments}}</small>
<small> {{$incexp->expense->title}}</small>**--get issue here**
<small>Кем создан: <strong>{{$incexp->user->name}}</strong></small>
</div>
<br>
<a href="/incexp/{{$incexp->id}}/edit" class="btn btn-primary">Edit</a>
{!! Form::open(['action'=>['IncomeExpenseController@destroy', $incexp->id], 'method' =>'POST', 'class'=>'float-right']) !!}
{{Form::hidden('_method', 'Delete')}}
{{Form::submit('Delete', ['class'=>'btn btn-danger'])}}
{!! Form::close() !!}
@stop
收入支出模式:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class IncomeExpenses extends Model
{
public function income(){
return $this->belongsTo('App\Income');
}
public function expense(){
return $this->belongsTo('App\Expenses');
}
public function user(){
return $this->belongsTo('App\User');
}
}
收入模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Income extends Model
{
public function incomeExpense(){
return $this->hasMany('App\IncomeExpenses');
}
}
费用模式:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Expenses extends Model
{
public function incomeExpense(){
return $this->hasMany('App\IncomeExpenses');
}
}