Closed NDanilov2015 closed 3 years ago
Hi,
This isn't directly supported out of the box; your best option would be to disable the frontend routes (forum.frontend.routes = false
) and define them yourself (either in your existing web routes file or a new one included via a service provider). Note that the Forum::route
helper might not work well with that approach depending on how you define the routes.
Another option would be to define your own routes, then override the existing ones by redefining them at some point later (via a service provider loaded after the forum one). Not the most elegant solution, but it would work.
I'll try to think of ways to make this easier to handle in version 5.
Hope that helps!
Hi!
Can you explain please in details, which distinction between routes which define in: a) /vendor/riari/laravel-forum/routes.php b) in Forum::route() helper
They are fully equivalent or no?
How best way redone Forum::route() helper to my own routes? Direct rewrite code to Route::group({$subdomain}) ?
I see very big distinctions about categories handler in:
a) /vendor/riari/laravel-forum/routes.php
$r->group(['prefix' => 'category', 'as' => 'category.'], function ($r) { $r->get('/', ['as' => 'index', 'uses' => 'CategoryController@index']); $r->post('/', ['as' => 'store', 'uses' => 'CategoryController@store']); $r->get('{id}', ['as' => 'fetch', 'uses' => 'CategoryController@fetch']); $r->delete('{id}', ['as' => 'delete', 'uses' => 'CategoryController@destroy']); $r->patch('{id}/enable-threads', ['as' => 'enable-threads', 'uses' => 'CategoryController@enableThreads']); $r->patch('{id}/disable-threads', ['as' => 'disable-threads', 'uses' => 'CategoryController@disableThreads']); $r->patch('{id}/make-public', ['as' => 'make-public', 'uses' => 'CategoryController@makePublic']); $r->patch('{id}/make-private', ['as' => 'make-private', 'uses' => 'CategoryController@makePrivate']); $r->patch('{id}/move', ['as' => 'move', 'uses' => 'CategoryController@move']); $r->patch('{id}/rename', ['as' => 'rename', 'uses' => 'CategoryController@rename']); $r->patch('{id}/reorder', ['as' => 'reorder', 'uses' => 'CategoryController@reorder']); });
b) in Forum::route() helper // Categories $router->post('category/create', ['as' => 'category.store', 'uses' => "{$controllers['category']}@store"]); $router->group(['prefix' => '{category}-{category_slug}'], function ($router) use ($controllers) { $router->get('/', ['as' => 'category.show', 'uses' => "{$controllers['category']}@show"]); $router->patch('/', ['as' => 'category.update', 'uses' => "{$controllers['category']}@update"]); $router->delete('/', ['as' => 'category.delete', 'uses' => "{$controllers['category']}@destroy"]);
Can you explain please meaning of this, I need keep alive helper Forum.php in workable state in my conversion of code.
Also, if function Forum::routeS() "Register the standard forum routes" - why yet need file /vendor/riari/laravel-forum/routes.php? I'm fully confused with your routing system. At first glance, they are identical, but a close look shows that there are small differences, please explain the meaning of partial duplication, partial difference?
The routes.php file from versions 3 and 4 of this package only contain API route definitions. The only way to get frontend routes with those versions is by installing the frontend package, where the routes are defined in Forum::routes()
(which is called in the service provider: https://github.com/Riari/laravel-forum-frontend/blob/1.0/src/ForumFrontendServiceProvider.php#L136).
Forum::route()
is just a shortcut to obtaining a URL for a given route.
At the moment, an attempt to copy routes to my web.php leads to the impossibility of displaying even the main page after disabling yours routing, 404 error. This forum is planned not as an additional one to some site, but as the whole site.
Frontend package used already)))
So I need edit frontend package Forum helper to working with my subdomains? And not touch to /vendor/riari/laravel-forum/routes.php ? I need working Forum helper with my own edits) (override "routes" method in App/Support ?)
Which routes did you copy? You should not get a 404 at /
if you copied the definitions from Forum::routes()
.
Actually, you might need to apply the outer group as well - see https://github.com/Riari/laravel-forum-frontend/blob/406a43144b95627339da1059c9c6a34569cc1156/src/ForumFrontendServiceProvider.php#L128
/vendor/riari/laravel-forum/routes.php - I understand now my error after your explains) Will try test with routes from helper.
The routes.php file from versions 3 and 4 of this package only contain API route definitions.
Forum::route()
is just a shortcut to obtaining a URL for a given route.
But why definitions API routes if we used only routes from Forum::routeS() for frontend? Which role they play in reality? If I will edit Forum::routeS() helper (or override it in App\Support\Forum.php), I can get workable subdomains as category names without edit /vendor/riari/laravel-forum/routes.php ?
The frontend package controllers internally dispatch requests to the API routes. This is covered in the docs: https://www.teamteatime.net/docs/laravel-forum/4.x/api/internal-dispatching/
Ok. When I try override Forum::routeS() method in my App\Support\Forum.php class, I get error:
Declaration of App\Support\Forum::routes(App\Support\Router $router) should be compatible with Riari\Forum\Frontend\Support\Forum::routes()
Possibly different arguments applied(((
But in code of forum as I know, calling App\Support\Forum class helper which must override your old Riari\Forum\Frontend\Support\Forum! Why not so, why overriding not working correctly?
on the other hand, if I will not touch your forum's package routing at all, in your opinion, is it possible to create subdomains instead of categories through the .htaccess file? First tests - give negative result, editing .htaccess about this theme give strange non-obvious behaviour of url links, which possibly get from combinations ".htaccess + your forum routes"
In index.php I write:
if (($_SERVER['SERVER_NAME'] == "xn--l1adgmc.club") && ($_SERVER['REQUEST_URI'] == "/2-bmv-forum-klub")) { header("Location: http://xn--90ac3a.xn--l1adgmc.club/2-bmv-forum-klub",TRUE,301); exit(); }
And this give me redirect from main site to subdomains with "human-read catalog name", e.g. forum.club/2-bmw-forum-klub to bmw.forum.club/2-bmw-forum-klub
Next, I want hide /2-bmw-forum-klub from such new url now without redirect to some another page, I write in .htaccess:
RewriteCond %{REQUEST_URI} ^/2-bmv-forum-klub RewriteRule ^2-bmv-forum-klub/(.*)$ https://bmw.forum.club/$1 [L,QSA]
This isn't working, possibly interfere with your forum engine router?
I'm not very familiar with Apache's mod_rewrite as it's been years since I last used it, but I think there are a few caveats even if you manage to get it working for a given URL, like redirects issued by the package's controllers.
Since Laravel's router does already support subdomain routing, I suggest you stick with defining your own routes. As long as the frontend routes are disabled and you use the same names (as
values) as the package routes, it should work - but as I said, it's not a supported feature so I'm afraid I can't help much beyond that.
I and my customer spent many hours to trying solve this problem, can I please suggest you (as inventor of forum) paid task to re-doing routing catalogs - on subdomains inside your vendor routing system? how much could it cost?
Unfortunately I don't really have time to commit to something like that - I try to allocate what little time I can spare for side projects to working on the new package version, which is getting close to being ready for its first stable release.
If you're really prepared to pay for the feature, you could try posting in a Laravel community such as Larachat (they have a #work channel where you can offer or seek work).
That said, I will try to spend a bit of time thinking about how this might be achieved in the new version, and if I come up with something that works nicely, I'll see about backporting it to version 4.
Hi! Now category format in url represent as like "https://_forum.site/category/thread/post_". How use subdomains with names equal category, like "https://_category.forum.site/thread/post_" for all content? I see you have a complex routing system, I would like to use something like:
Route::group(['domain' => '{subdomain}.forum.site'], function () {
in router file like /vendor/riari/laravel-forum/routes.php
Also, how publish it to it not changing if I update package?