Laravel 5.6 - Grab message from Controller into view
up vote
0
down vote
favorite
I'm starting with Laravel and i need to show the output of a post request into the view. My controller file returns an array with a message, like this:
return redirect('/myroute')
->with('message', [
'type' => 'success',
'text' => 'It works'
]);
In my view file, i'm trying to grab the message text, but no success. See my code below
@if(Session::has('message'))
$msg = Session::get('message')
<h4> $msg->text </h4>
@endif
The point is: The condition works, if i changed the $msg->text to any text it works, but when i try to get the message text, it returns an error:
htmlspecialchars() expects parameter 1 to be string, array given
So, any help is apreciated. If more information is needed, just ask.
PS: i checked this question, but no success at all
EDITED:
PS2: Can't change controller structure
php laravel
add a comment |
up vote
0
down vote
favorite
I'm starting with Laravel and i need to show the output of a post request into the view. My controller file returns an array with a message, like this:
return redirect('/myroute')
->with('message', [
'type' => 'success',
'text' => 'It works'
]);
In my view file, i'm trying to grab the message text, but no success. See my code below
@if(Session::has('message'))
$msg = Session::get('message')
<h4> $msg->text </h4>
@endif
The point is: The condition works, if i changed the $msg->text to any text it works, but when i try to get the message text, it returns an error:
htmlspecialchars() expects parameter 1 to be string, array given
So, any help is apreciated. If more information is needed, just ask.
PS: i checked this question, but no success at all
EDITED:
PS2: Can't change controller structure
php laravel
Have you checked what$msgexactly contains? Try dumping it in the controller to see whether it is an array, an object, a string,......
– Nico Haase
Nov 9 at 14:53
@NicoHaase i tried to dump it var_dump($msg) inside template but still got the same error
– danielarend
Nov 9 at 15:14
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm starting with Laravel and i need to show the output of a post request into the view. My controller file returns an array with a message, like this:
return redirect('/myroute')
->with('message', [
'type' => 'success',
'text' => 'It works'
]);
In my view file, i'm trying to grab the message text, but no success. See my code below
@if(Session::has('message'))
$msg = Session::get('message')
<h4> $msg->text </h4>
@endif
The point is: The condition works, if i changed the $msg->text to any text it works, but when i try to get the message text, it returns an error:
htmlspecialchars() expects parameter 1 to be string, array given
So, any help is apreciated. If more information is needed, just ask.
PS: i checked this question, but no success at all
EDITED:
PS2: Can't change controller structure
php laravel
I'm starting with Laravel and i need to show the output of a post request into the view. My controller file returns an array with a message, like this:
return redirect('/myroute')
->with('message', [
'type' => 'success',
'text' => 'It works'
]);
In my view file, i'm trying to grab the message text, but no success. See my code below
@if(Session::has('message'))
$msg = Session::get('message')
<h4> $msg->text </h4>
@endif
The point is: The condition works, if i changed the $msg->text to any text it works, but when i try to get the message text, it returns an error:
htmlspecialchars() expects parameter 1 to be string, array given
So, any help is apreciated. If more information is needed, just ask.
PS: i checked this question, but no success at all
EDITED:
PS2: Can't change controller structure
php laravel
php laravel
edited Nov 9 at 14:48
asked Nov 9 at 14:09
danielarend
326312
326312
Have you checked what$msgexactly contains? Try dumping it in the controller to see whether it is an array, an object, a string,......
– Nico Haase
Nov 9 at 14:53
@NicoHaase i tried to dump it var_dump($msg) inside template but still got the same error
– danielarend
Nov 9 at 15:14
add a comment |
Have you checked what$msgexactly contains? Try dumping it in the controller to see whether it is an array, an object, a string,......
– Nico Haase
Nov 9 at 14:53
@NicoHaase i tried to dump it var_dump($msg) inside template but still got the same error
– danielarend
Nov 9 at 15:14
Have you checked what
$msg exactly contains? Try dumping it in the controller to see whether it is an array, an object, a string,......– Nico Haase
Nov 9 at 14:53
Have you checked what
$msg exactly contains? Try dumping it in the controller to see whether it is an array, an object, a string,......– Nico Haase
Nov 9 at 14:53
@NicoHaase i tried to dump it var_dump($msg) inside template but still got the same error
– danielarend
Nov 9 at 15:14
@NicoHaase i tried to dump it var_dump($msg) inside template but still got the same error
– danielarend
Nov 9 at 15:14
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
Try accessing the array as follows:
<h4> $msg['text'] </h4>
or just pass an array with the items
->with([
'type' => 'success',
'text' => 'It works'
]);
//in the view
@if(session()->has('text'))
<h4> session('text') </h4>
@endif
-- EDIT
iterate than over the session like so:
@foreach (Session::get('message') as $msg)
$msg['text']
@endforeach
you can read more about that here
It didn't wok for me, same error. Can't change controller structure. I tried also $msg->text and error persist.
– danielarend
Nov 9 at 14:46
Then you have to iterate over the session in order to access your items. Look at my Edit above
– nakov
Nov 9 at 14:53
Thanks a lot, but still not working, Error message now is 'Illegal string offset 'text''
– danielarend
Nov 9 at 15:09
try tovar_dumpthe content of the$msgwithin the view and see what it has, something is missing there so I cannot debug it when I don't have the code.
– nakov
Nov 9 at 16:04
add a comment |
up vote
0
down vote
Do this instead
return redirect('/myroute')->with('success','It worked');
Then on your view
session('success')
New contributor
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Unfornunatelly i can't change controller structure
– danielarend
Nov 9 at 15:10
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Try accessing the array as follows:
<h4> $msg['text'] </h4>
or just pass an array with the items
->with([
'type' => 'success',
'text' => 'It works'
]);
//in the view
@if(session()->has('text'))
<h4> session('text') </h4>
@endif
-- EDIT
iterate than over the session like so:
@foreach (Session::get('message') as $msg)
$msg['text']
@endforeach
you can read more about that here
It didn't wok for me, same error. Can't change controller structure. I tried also $msg->text and error persist.
– danielarend
Nov 9 at 14:46
Then you have to iterate over the session in order to access your items. Look at my Edit above
– nakov
Nov 9 at 14:53
Thanks a lot, but still not working, Error message now is 'Illegal string offset 'text''
– danielarend
Nov 9 at 15:09
try tovar_dumpthe content of the$msgwithin the view and see what it has, something is missing there so I cannot debug it when I don't have the code.
– nakov
Nov 9 at 16:04
add a comment |
up vote
3
down vote
Try accessing the array as follows:
<h4> $msg['text'] </h4>
or just pass an array with the items
->with([
'type' => 'success',
'text' => 'It works'
]);
//in the view
@if(session()->has('text'))
<h4> session('text') </h4>
@endif
-- EDIT
iterate than over the session like so:
@foreach (Session::get('message') as $msg)
$msg['text']
@endforeach
you can read more about that here
It didn't wok for me, same error. Can't change controller structure. I tried also $msg->text and error persist.
– danielarend
Nov 9 at 14:46
Then you have to iterate over the session in order to access your items. Look at my Edit above
– nakov
Nov 9 at 14:53
Thanks a lot, but still not working, Error message now is 'Illegal string offset 'text''
– danielarend
Nov 9 at 15:09
try tovar_dumpthe content of the$msgwithin the view and see what it has, something is missing there so I cannot debug it when I don't have the code.
– nakov
Nov 9 at 16:04
add a comment |
up vote
3
down vote
up vote
3
down vote
Try accessing the array as follows:
<h4> $msg['text'] </h4>
or just pass an array with the items
->with([
'type' => 'success',
'text' => 'It works'
]);
//in the view
@if(session()->has('text'))
<h4> session('text') </h4>
@endif
-- EDIT
iterate than over the session like so:
@foreach (Session::get('message') as $msg)
$msg['text']
@endforeach
you can read more about that here
Try accessing the array as follows:
<h4> $msg['text'] </h4>
or just pass an array with the items
->with([
'type' => 'success',
'text' => 'It works'
]);
//in the view
@if(session()->has('text'))
<h4> session('text') </h4>
@endif
-- EDIT
iterate than over the session like so:
@foreach (Session::get('message') as $msg)
$msg['text']
@endforeach
you can read more about that here
edited Nov 9 at 14:54
answered Nov 9 at 14:12
nakov
1,17878
1,17878
It didn't wok for me, same error. Can't change controller structure. I tried also $msg->text and error persist.
– danielarend
Nov 9 at 14:46
Then you have to iterate over the session in order to access your items. Look at my Edit above
– nakov
Nov 9 at 14:53
Thanks a lot, but still not working, Error message now is 'Illegal string offset 'text''
– danielarend
Nov 9 at 15:09
try tovar_dumpthe content of the$msgwithin the view and see what it has, something is missing there so I cannot debug it when I don't have the code.
– nakov
Nov 9 at 16:04
add a comment |
It didn't wok for me, same error. Can't change controller structure. I tried also $msg->text and error persist.
– danielarend
Nov 9 at 14:46
Then you have to iterate over the session in order to access your items. Look at my Edit above
– nakov
Nov 9 at 14:53
Thanks a lot, but still not working, Error message now is 'Illegal string offset 'text''
– danielarend
Nov 9 at 15:09
try tovar_dumpthe content of the$msgwithin the view and see what it has, something is missing there so I cannot debug it when I don't have the code.
– nakov
Nov 9 at 16:04
It didn't wok for me, same error. Can't change controller structure. I tried also $msg->text and error persist.
– danielarend
Nov 9 at 14:46
It didn't wok for me, same error. Can't change controller structure. I tried also $msg->text and error persist.
– danielarend
Nov 9 at 14:46
Then you have to iterate over the session in order to access your items. Look at my Edit above
– nakov
Nov 9 at 14:53
Then you have to iterate over the session in order to access your items. Look at my Edit above
– nakov
Nov 9 at 14:53
Thanks a lot, but still not working, Error message now is 'Illegal string offset 'text''
– danielarend
Nov 9 at 15:09
Thanks a lot, but still not working, Error message now is 'Illegal string offset 'text''
– danielarend
Nov 9 at 15:09
try to
var_dump the content of the $msg within the view and see what it has, something is missing there so I cannot debug it when I don't have the code.– nakov
Nov 9 at 16:04
try to
var_dump the content of the $msg within the view and see what it has, something is missing there so I cannot debug it when I don't have the code.– nakov
Nov 9 at 16:04
add a comment |
up vote
0
down vote
Do this instead
return redirect('/myroute')->with('success','It worked');
Then on your view
session('success')
New contributor
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Unfornunatelly i can't change controller structure
– danielarend
Nov 9 at 15:10
add a comment |
up vote
0
down vote
Do this instead
return redirect('/myroute')->with('success','It worked');
Then on your view
session('success')
New contributor
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Unfornunatelly i can't change controller structure
– danielarend
Nov 9 at 15:10
add a comment |
up vote
0
down vote
up vote
0
down vote
Do this instead
return redirect('/myroute')->with('success','It worked');
Then on your view
session('success')
New contributor
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Do this instead
return redirect('/myroute')->with('success','It worked');
Then on your view
session('success')
New contributor
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Nov 9 at 14:17
Paul Mikki
583
583
New contributor
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Paul Mikki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Unfornunatelly i can't change controller structure
– danielarend
Nov 9 at 15:10
add a comment |
Unfornunatelly i can't change controller structure
– danielarend
Nov 9 at 15:10
Unfornunatelly i can't change controller structure
– danielarend
Nov 9 at 15:10
Unfornunatelly i can't change controller structure
– danielarend
Nov 9 at 15:10
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227294%2flaravel-5-6-grab-message-from-controller-into-view%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Have you checked what
$msgexactly contains? Try dumping it in the controller to see whether it is an array, an object, a string,......– Nico Haase
Nov 9 at 14:53
@NicoHaase i tried to dump it var_dump($msg) inside template but still got the same error
– danielarend
Nov 9 at 15:14