0

I'm doing maintenance for a system, and all looks good, the response is a array, but...

Error:

    ErrorException in 50d38bdad3300f6dc00fd1e48a69e7c853b48bcb.php line 146:
Trying to get property of non-object (View: /home/sistemamoney/office/resources/views/admin/pages/saque.blade.php)

Files:

saque.blade.php (line 137 to 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 (Inject)

<?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, '');
    }

}

I really don't know what is the problem, because it all looks ok...

  • So its this line? `$cpf=App\User::where('id',$saque->user_id)->first()->cpf;` kinda looks out of place. – Lawrence Cherone Mar 22 '18 at 21:34
  • 1
    Perhaps `first()` does not return on one or all of the objects :/ – Lawrence Cherone Mar 22 '18 at 21:35
  • App\User::where('id',$saque->user_id)->first() returns and empty object at some point and you get that error. See if that id actually exists and if it's not deleted with soft deletes – Indra Mar 22 '18 at 21:38
  • in php 7.2 (7.1 as well maybe) you can do App\User::where('id',$saque->user_id)->first()->cpf ?? null and you will get null when not available without any erorrs – Indra Mar 22 '18 at 21:42
  • 1
    https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php – ficuscr Mar 22 '18 at 21:43
  • show us line 146 of `50d38bdad3300f6dc00fd1e48a69e7c853b48bcb.php` not `saque.blade.php`. Most of the time, the line number will not sync with the original blade since the former is a compiled version of the latter – Wreigh Mar 23 '18 at 01:18
  • Fixed. user_id changed to id – Carlos Daniel Giovanella Mar 23 '18 at 03:11

0 Answers0