I have problem when passing the retrieved data to the view (using redirect()->back()-with()
)
I have a method in my controller, after the data retrieved, I make new variable called $data
and send it to the view, like this
$message = Message::find($request->id);
$data = [
"{$do}Modal" => "{$do}Modal",
'msg' => $message
];
return redirect()->back()->with($data);
Then, in my view, I need to initiate new variable for the data, $msg
. But I got an error that says the variable is an array when I want to show it.
@php
$msg = Session::get('msg')
@endphp
// it shows 1 ($msg is an object)
// the error message shown up
// shows the id
My first intension is to show up the id, title, etc as an object, but I only can show the values as an array. When I did var_dump($msg)
, a got this output:
object(App\Models\Message)#200 (26) {
["fillable":protected]=>
array(4) {
[0]=>
string(5) "title"
[1]=>
string(4) "body"
[2]=>
string(8) "password"
[3]=>
string(5) "image"
}
["connection":protected]=>
string(5) "mysql"
["table":protected]=>
string(8) "messages"
["primaryKey":protected]=>
string(2) "id"
["keyType":protected]=>
string(3) "int"
["incrementing"]=>
bool(true)
["with":protected]=>
array(0) {
}
["withCount":protected]=>
array(0) {
}
["perPage":protected]=>
int(15)
["exists"]=>
bool(true)
["wasRecentlyCreated"]=>
bool(false)
["attributes":protected]=>
array(7) {
["id"]=>
int(101)
["title"]=>
string(19) "Tes ketiga hari ini"
["body"]=>
string(18) "sfkafaf
afaf
afa"
["created_at"]=>
string(19) "2019-12-03 11:20:56"
["updated_at"]=>
string(19) "2019-12-03 11:39:29"
["password"]=>
string(60) "$2y$10$hSTdJZN24aIddOjrGMmUceYN1cPFvLM.IjCcEL/BPb/4C6ayk12va"
["image"]=>
string(91) "kala-gotongan-dan-semut-sadulur-pantang-kubur-jenazah-ini-alasannya_m_39626_1575343256.jpeg"
}
["original":protected]=>
array(7) {
["id"]=>
int(101)
["title"]=>
string(19) "Tes ketiga hari ini"
["body"]=>
string(18) "sfkafaf
afaf
afa"
["created_at"]=>
string(19) "2019-12-03 11:20:56"
["updated_at"]=>
string(19) "2019-12-03 11:39:29"
["password"]=>
string(60) "$2y$10$hSTdJZN24aIddOjrGMmUceYN1cPFvLM.IjCcEL/BPb/4C6ayk12va"
["image"]=>
string(91) "kala-gotongan-dan-semut-sadulur-pantang-kubur-jenazah-ini-alasannya_m_39626_1575343256.jpeg"
}
["changes":protected]=>
array(0) {
}
["casts":protected]=>
array(0) {
}
["dates":protected]=>
array(0) {
}
["dateFormat":protected]=>
NULL
["appends":protected]=>
array(0) {
}
["dispatchesEvents":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["relations":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["timestamps"]=>
bool(true)
["hidden":protected]=>
array(0) {
}
["visible":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire