我正在为一个系统做维护,一切看起来不错,响应是一个数组,但是......
错误:的
ErrorException in 50d38bdad3300f6dc00fd1e48a69e7c853b48bcb.php line 146:
Trying to get property of non-object (View: /home/sistemamoney/office/resources/views/admin/pages/saque.blade.php)
文件:
saque.blade.php (第137至165行......)
@inject('Saque', 'App\Saque')
<?php
if (is_numeric(@$_GET['status']) and isset($_GET['status'])) {
$stat = $_GET['status'];
$saques = $Saque->where('status',$stat)->orderBy('id')->get();
} else {
$saques = $Saque->orderBy('id')->get();
}
?>
@foreach($saques as $saque)
<?php
$cpf=App\User::where('id',$saque->user_id)->first()->cpf;
?>
<tr>
<td>{{$saque->id}}</td>
<td>{{$saque->username($saque->user_id)}}</td>
<td>{{App\User::where('id',$saque->user_id)->first()->name}}</td>
<td>{{App\User::where('id',$saque->user_id)->first()->telefone}}</td>
<td>{{App\User::where('id',App\User::where('id',$saque->user_id)->first()->pai_id)->first()->name}}</td>
<td>{{$cpf}}</td>
<td>{{$saque->mensagem}}</td>
<td>{{$saque->created_at}}</td>
<td><a onclick="updateStatus({{$saque->id}},'{{getStatus($saque->status)}}')">{{getStatus($saque->status)}}(mudar)</a></td>
<td>R$ {{@number_format($saque->valor, 2, ',', '.')}}</td>
<td>{{$saque->data_deposito}}</td>
<td>{{strip_tags($saque->conta)}}</td>
</tr>
@endforeach
App \ Saque (注入)
<?php
namespace App;
Use Str;
use Illuminate\Database\Eloquent\Model;
class Saque extends Model {
protected $fillable = ['valor', 'created_at', 'status', 'user_id', 'data_deposito', 'conta', 'mensagem'];
public function username($id) {
$dat = User::where('id', $id)->first();
return strlen(Str::words($dat['username'], 1, '')) <= 5 ? Str::words($dat['username'], 2, '') : Str::words($dat['username'], 1, '');
}
}
我真的不知道是什么问题,因为一切看起来都不错......