9 months ago

Models not accessible after creating subdomains

Posted 9 months ago by divinulledivi

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.


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



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.