I realized something I can't figure out by myself.
I get a different result when I loop through first in a Controller and pass then the result to my view. Versus loop straight in my view.
For instance: I have this in my Controller:
public function index()
{
$subscribers = Subscriber::where('user_id', Auth::user()->id)->orderBy('created_at','asc')->get();
foreach ($subscribers as $key => $subscriber) {
$var = $subscriber->name;
}
return view('backend.newsletter.contacts.index')->withSubscribers($subscribers)
->withVar($var);
}
by using {{$var}} in my view I get only "John" as a result.
But when I use the foreach loop in my view instead of in the Controller:
@foreach($subscribers as $key => $subscriber)
{{$subscriber->name}}
@endforeach
I get two results, "John" and "Dan". This makes totaly sense as I have two entries in my DB.
So how does it come that I get two different results here ?