Reputation: 88
I'm getting an error of
htmlspecialchars() expects parameter 1 to be string, object given.
I'm trying to print an array
from session
to blade.
view:
<input type="text" name="to" value="{{$mail}}">
controller:
public function view_send_email()
{
$data["_email_list"] = Tbl_press_release_email::get();
$data["sent_email"] = Request::input('sent_email');
$mail = Session::get('email');
return view("send_email", compact('data', 'mail'));
}
Upvotes: 2
Views: 2583
Reputation: 21681
You should try this:
@foreach ($mail as $email)
<input type="text" name="to[]" value="{{$email}}">
@endforeach
Note: As you will have multiple values in $email
you need to take array of input element as mentioned in above code (i.e name = "to[]"
)
Updated Answer
@foreach ($mail as $email)
@foreach ($mail as $emails)
<input type="text" name="to[]" value="{{$emails}}">
@endforeach
@endforeach
Upvotes: 1
Reputation: 5395
It seems like it's returning multiple values, so you have to loop through them to display all of them, use a foreach
loop.
@foreach ($mail as $email)
<input type="text" name="to" value="{{$email}}">
@endforeach
If you want Form Model Binding
That's a different thing but the same concept, you can view the docs here.
EDIT: It looks like you want to store an array into an input, to do this you must add a []
at the end of the name of your input like this
<input type="text" name="to[]" value="{{$mail}}">
Then when they submit you simply go Input::get('to')[0]
to display the first input.
Upvotes: 0
Reputation: 145
<input type="text" name="to" value="{{$mail}}">
To
<input type="text" name="to" value="{{print_r($mail)}}">
Upvotes: 0