Kaustubh
1 year ago

Dynamic routes

Posted 1 year ago by Kaustubh

Route

Route::get('{communityName}', '[email protected]')->name('test');

Controller

public function test($CommunityName)
{
    $community = Community::where('communityName',$CommunityName)->get();
    if(!$community)
    {
        return redirect()->route($community);
    }

    return view('layouts.Community',compact('community'));
}

Here i want to redirect to community page if it is present in table and if that name not present in table then it should redirect to specific route

for eg. // Should redirect to community page http://localhost/community/public/DUMMYCOMMUNITY

// Should redirect to login page http://localhost/community/public/login

But this process is going in an infinite loop. is there any best way to achive this

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