memele
3 months ago

Models not accessible after creating subdomains

Posted 3 months ago by memele

I created dynamic subdomain routes for my forum. The homepage works just fine with listing all discussions related to the subdomain. I moved the route for showing a single discussion inside the subdomain route group and it broke. When I try to access a discussion I get Trying to get property 'title' of non-object. The Model returns null.

web.php

Route::domain('{forum}.frm.test')->group(function () {

    Route::get('/', '[email protected]'); // Works just fine


    //Discussion routes

    Route::get('/discussion/{id}/{slug}', '[email protected]'); // Returns the error

});

DiscussionController

public function show($id, $slug)
    {
        $discussion = Discussion::where('id', $id)->where('slug', $slug)->with('user')->with('category')->first();

        return view('discussion.show')->with(['discussion' => $discussion]);
    }

What am I missing here? Why is the '/' route working but not the single discussion view?

Please sign in or create an account to participate in this conversation.