0
I’m new and I’d like some help, I have a controller carrying out a consultation.
Controller
$user = $this->user->find('1');
view('index', compact('user'));
View
@forelse ($user as $u)
<h1>{{ $u->name }}</h1>
@endforeach
In the View would need to put some extra field example: active, but would not like to touch the database just put a field and access the
{{ $u->ativo }}
I hope I was clear.
For clarification...
user was just an example, instead of passing one more object to View in the Controller would like to change this object and include items in it, let’s say step one user and a post instead of making a new foreach.
Instead:
view('index', compact('user'),compact('post'));
would like
view('index', compact('user'));
Note: user or other name example only.
Instead:
View
<h1>{{ $user->name }}</h1>
@forelse ($post as $u)
<h1>{{ $u->name }}</h1>
@endforeach
that:
@forelse ($user as $u)
<h1>{{ $u->name }}</h1>
<h1>{{ $u->Postname }}</h1>
@endforeach
I hope the explanation gets better.
First, the controller returns a user, just one, I don’t know how it managed to make one
foreach, it was not clear that, and something else that was not clear, what is the corresponding value to generate an additional field where it has no relation to its basis, that theEloquentmakes, but, he needs to know the value, which would be a calculated field addition. Could explain better?– novic
I edited the question to clarify, this is a link of something similar creating in array more https://stackoverflow.com/a/48857855/10569172, instead of using name["name"] I would like to use name->name.. if possible... thank you
– Sidiclei F. Almeida
Sidiclei, you didn’t explain better, got worse (kkkkkkkkkkkkk) boy if you want to join several objects in an object, why? It will increase the complexity, now if you have relationship between them the ownFramework Eloquentdoes it for you, just call the relationship with the commandwithwhich is best suited for being optimized. It is no use to create a question that is not your reality, create as you need, and do not put fictitious examples that do not help you to clarify your problem, for exampleUserandPostcan have relationship, but, I do not know if it is your reality.– novic