Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RyanCarlson's avatar

How to load all front end pages the same for different users with /id or /username?

I want to give the admin the ability to build front end landing pages that are built the same except for some unique data pulled up on each page for different users when /id or eventually /username is entered at the end of the page URL.

domain/pagename

Would load the page with admin picture on it where {{picture}} is entered in blade file.

domain/pagename/id or domain/pagename/username

Would load the same page but with the users picture on it where {{picture}} is entered in blade file.

I need the admin to be able to build the pages their self with a page builder and not have to add routes for each page. So I need to know the best way to accomplish this so that all front end pages get this function automatically applied to all front end pages.

I'm new to Laravel and I really appreciate any assistance you can offer on this.

I'm starting off using code generated from an opensource GrapesJS page builder.

routes/frontend.php

use Illuminate\Support\Facades\Route;
use MSA\LaravelGrapes\Http\Controllers\FrontendController;
Route::get('pagename', [FrontendController::class, 'Page1']);
Route::get('page2name', [FrontendController::class, 'Page2']);

Http/Controllers/FrontendController.php

namespace MSA\LaravelGrapes\Http\Controllers;
use Illuminate\Http\Request;
use MSA\LaravelGrapes\Http\Controllers\Controller;
class FrontendController extends Controller
{
    public function Page1()
    {
        return view('lg::pages/pagename');
    }
    public function Page2()
    {
       return view('lg::pages/page2name');
    }
}
0 likes
2 replies
tykus's avatar

Use an optional route parameter for the id or username, so the domain/pagename and domain/pagename/id URLs are handled by the same Controller:

Route::get('domain/{pagename}/{id?}', PageController::class)->name('pages.show');
class PageController
{
    public function __invoke(Request $request, $pagename, $id = null) 
    {
        $user = $id ? User::find($id) : $request->user();

	    $image = $user->profile_picture;

        // ...

        return view('page.show', compact('image', /* other data*/);
    }
}
RyanCarlson's avatar

@tykus I couldn't figure that out. Maybe you could look at my updated post with code blocks?

Please or to participate in this conversation.