Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Separate frontend and backend


Anyone can help me to separate frontend and backend routes in Metronic laravel version?
Thanks !


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (7)


Hi,

You have to customize it. At the moment, Metronic does not have an example for it.

You could also split your admin routes into a separate file, and require that file in your app/routes.php file. With separate route for / and /admin.

Thanks



I tried to customize it, but when i change routes files and get back to initial code:

// Route::get('/', function () {
// return redirect('index');
// });

But when i try this, authentication and menu doesn't work anymore.

I don't know how to handle this:
$menu = theme()->getMenu();
array_walk($menu, function ($val) {
if (isset($val['path'])) {
$route = Route::get($val['path'], [PagesController::class, 'index']);

// Exclude documentation from auth middleware
if (!Str::contains($val['path'], 'documentation')) {
$route->middleware('auth');
}

// Custom page demo for 500 server error
if (Str::contains($val['path'], 'error-500')) {
Route::get($val['path'], function () {
abort(500, 'Something went wrong! Please try again later.');
});
}
}
});

I know how to do this with initial laravel files, but metronic was customized in another way.

Thanks !



The way i manage separation for frontend and backend routes is as follows:

create a helper:


if (! function_exists("includeFilesInFolder")) {
/**
* Loops through a folder and requires all PHP files
* Searches sub-directories as well.
*
* @param $folder
*/
function includeFilesInFolder($folder)
{
try {
$rdi = new RecursiveDirectoryIterator($folder);
$it = new RecursiveIteratorIterator($rdi);

while ($it->valid()) {
if (! $it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === "php") {
require $it->key();
}

$it->next();
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}

if (! function_exists("includeRouteFiles")) {

/**
* @param $folder
*/
function includeRouteFiles($folder)
{
includeFilesInFolder($folder);
}
}


then on routes/web.php:


/*
* Frontend Routes
*/
Route::name("frontend.")->group(function () {
includeRouteFiles(__DIR__."/frontend/");
});

/*
* Backend Routes
*/
Route::prefix("admin")->name("admin.")->middleware("auth")->group(function () {
includeRouteFiles(__DIR__."/backend/");
});


then under routes folder create the two folders (frontend and backend) and just create your route files in there, for example:

under routes/frontend create an auth.php file and add:


<?php

Route::group(["middleware" => "guest"], function () {
// Authentication
Route::get("login", [LoginController::class, "showLoginForm"])->name("login");
Route::post("login", [LoginController::class, "login"])->name("login.post");
});


then under routes/backend create an admin.php file and add for example:


<?php

Route::redirect("/", "/admin/dashboard", 301)->name("redirect");


that way you have your routes separated by frontend and backend happy



Thank you Carlos and appreciate your efforts. Hope this can help others as well happy

Thanks



Great.
I will try this
Thank you !



under routes/frontend create an auth.php file and add:


<?php

Route::group(["middleware" => "guest"], function () {
// Authentication
Route::get("login", [LoginController::class, "showLoginForm"])->name("login");
Route::post("login", [LoginController::class, "login"])->name("login.post");
});


then under routes/backend create an admin.php file and add for example:


<?php

Route::redirect("/", "/admin/dashboard", 301)->name("redirect");


that way you have your routes separated by frontend and backend happy



I tried your version but for now not working. I will try to search for another method.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(