oscarotero / Embed

Get info from any web service or page
MIT License
2.08k stars 311 forks source link

difficulty previewing url #482

Open Temian1 opened 2 years ago

Temian1 commented 2 years ago

I am on laravel 9 in my show blade I am trying to display any URL posted by a user here is my code

in my livewire post show blade I did this if I create a post with a link the is not previewing in my show view page , I have tried to different URL still not working

public function mount (Post $post)
{
     $this->post = $post;

    preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $post->body, $matches);
    $this->urlDetails = collect($matches[0])->map(function ($url) {
       $embed = new Embed();
       $info = $embed->get($url);
        return ['info' => $info, 'title' => $info->title];  
    })->all();
}

getting the URL like this in my show blade view

{{ $urlDetails['title'] ?? '' }}

but it's not working

oscarotero commented 2 years ago

Sorry I'm not familiarized with Laravel so cannot help.