1

Controller :

$args = array();
$args['name'] = "Robin";
$args['email'] = "asdasd@asdasd.net";
$clientpayments = Payments::getPaymentByClient($id);
$args['activity'] = $clientpayments;
return view('clients.show',["args" => $args]); 

View:

{{ $args->name }}
{{ $args->email }}

@if (isset($args['activity']))        
@foreach ($args['activity'] as $act)
{{$act->job_name}}
@endforeach
@endif;

So what the issue is is that $activity loop works fine but the $name and $email is returning a non-object error... Any ideas to where I'm going wrong?

Thanks!

user608207
  • 39
  • 2

3 Answers3

1

Since you're using an array, change this:

{{ $args->name }}
{{ $args->email }}

To:

{{ $args['name'] }}
{{ $args['email'] }}
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

You are trying to access an object value, but you are sending an array to your view.

$payments = Payments::getPaymentByClient($id);

$args = array([
  'name' => 'Robin',
  'email' => 'asdasd@asdasd.net',
  'activity' => $payments, // Expecting a collection
]);

return view('clients.show', [
  "args" => (object) $args // Cast into an object
]); 

Blade template (if you have an object)

{{ $args->name }}
{{ $args->email }}

// If your activity is a collection
@foreach ($args->activity as $act)
  {{ $act->job_name }}
@endforeach

Blade template (if you have an array)

{{ $args['name'] }}
{{ $args['email'] }}

// If your activity is a collection
@foreach ($args['activity'] as $act)
  {{ $act->job_name }}
@endforeach
Eduardo Stuart
  • 2,869
  • 18
  • 22
0

Got it.

A silly mistake, but I'm just learning Laravel. I was including $args in the View rather than just $name, $email and $activity which worked perfectly.

Thanks anyway.

user608207
  • 39
  • 2