Make Route Model Binding for Video (Working)

Hello , I'd hoped you could help me make what I already have a little cleaner. The goal: Show a Video on the Website (Uploaded File via Voyager file upload). What i have: My Route:

Route::get('/post/{slug}', "[email protected]");

Which lets me click on a post and i get the


    public function showPost($slug)
        $post = Post::where("slug", $slug)->first();

        return view('posts.post_view', compact("post"));

And in that post_view.blade.php i simply say

   $json = json_decode($post->video_hash, true);
    $path = $json[0]['download_link'];

because the video URL is stored in the video_hash row in the posts table. this way i get the URL posts/folder/filename.fileextension (e.g. posts/february/bbb.mp4)

Now to my question: How do i get this exact same result with Route model binding? Is it possible ? Because my Route leads me to my post slug, can i register another route for this and if this is possible would you be as kind as to explain thoroughly how to do it? Thanks a ton!

Cameron replied 2 months ago

Are you trying to get the download link directly through a route binding ?

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us