1

does anyone know why database notification url added \ on //?

scenery

I have a notification table I want to store a url as data array inside notification class , but the url get added \ , below is my code, when I using the eloquent url is not getting strip meaning store whatever I pass in database.

public function toDatabase()
{
    return [
        // 'msg' => "Your Comment On ". $this->post->getAttributes()['title'] ." Was Approved Please click <a href='".route('$this->post->slug')."'>here</a> to view it",

        'msg' => "https://google.com" ,
    ];
}

what is actually store inside my db when I invoke the notify class

{"msg":"https:\/\/google.com"}

look like they have added mysql prevention, but query builder is injection-free as stated on the doc correct me if I am wrong thanks

Lowity
  • 91
  • 9
Leong
  • 139
  • 13

2 Answers2

1

What actually stored in your notification table is a json format as you can seen it's key:value pair json

{"msg":"https:\/\/google.com"}

to get the data of your notificaiton you need to json_decode() the data like so

json_decode($notification->data);

you can also, refer to this question "why-are-forward-slashes-escaped" to know more about escaping forward slash

mmabdelgawad
  • 2,385
  • 2
  • 7
  • 15
0

another turn around I come up is the encode the url then store inside db

Leong
  • 139
  • 13