Modify the URL generated with Route::apiResource without changing the name - laravel

I'm building a website where users can post ads : a VueJS app that requests routes on an Laravel API.
I have an AdController, with an Ad model, and my routing is done via stuff like :
Route::apiResource('ads', AdController::class)->only(['update', 'destroy']);
Route::apiResource('ads.photos', AdPhotoController::class)->only(['index']);
which generates routes like PUT "/ads/{ad}" or GET "/ads/{id}/photos"....
This works very well, and my VueJS app uses Ziggy to call the API by their route name
axios.get(route('ads.photos.index', id))
And... It still works flawlessly ! No problem at all, and I have a LOT of routes with a LOT of API calls.
Now my problem : we realised that URLs containing "ads" are blocked by adblockers. That completely shuts down all access to our website, and asking users to turn off the adblocker is NOT a solution.
I could change my routes to do something like
Route::apiResource('posts.photos', AdPhotoController::class)->only(['index']);
but I have a LOT of routes and I really don't want to rename everything, everywhere.
Is there an option to change apiResources generated URL, so 'ads.photos.index' would generate "/posts/{id}/photos" instead of "/ads/{id}/photos" ?

Related

Laravel is not accepting GET API request without any parameter

I am making APIs in Laravel version 8.x for a third party system. For this, I have created few APIs and all routes are mentioned in routes/api.php
In our system, there are few APIs that can be accessible via GET request, that returns data without any authentication and parameters. Look at the routes below in api.php:
//routes/api.php
Route::group(['namespace' => 'App\Http\Controllers\WebServices'], function() {
Route::get('event_types', 'EventWs#getEventTypes');
Route::get('event_type/{event_type_id}', 'EventWs#getEventTypeById');
});
Look at the both routes above. The route having segment is working fine with GET request, but the route without any segment is not calling. This is just a simple GET request without any segment or query string.
I am working on Laravel from past few months, but this issue is strange to me. May be there could be some kind of middleware that prevent GET (without segment or query string) route execution. But I am not able to find reason or that unknown barrier.
Have anyone idea about why this happening or I am missing something?
Please Note that I am using Laravel 8.x

Laravel Multi-Tenant Multi-Database Multi-Domain - Problem with default route

I'm studying about multi-tenant with Laravel and I'm having a problem with the routes. The main application works fine, however the main client domain (route / ) returns the 401 error configured in the middleware I created, but the other routes (login, register, etc) work perfectly.
If I put a prefix on the main application routes, then the / client route works normally, but I need the main application not to have a prefix since I want to use it to create the service submission and hiring system.
Anyone who has knowledge on this subject and can take a look at my code and help me find out why only the route is returning this error I will be very grateful.
If i access app.mydefaultapp works
If i access app.myclientapp doesn't works
If i access app.myclientapp/login(or any other route) works
https://pastebin.com/bHHux9sY
I solved the problem by creating a Provider with the same Middleware identification logic, and when accessing the main domain it dynamically loads the routes of the main domain.
$manager = app(ManagerTenant::class);
if ($manager->domainIsMain())
{
$this->registerTenantRoutes();
$this->registerTenantAdminRoutes();
}
https://pastebin.com/20SCsgfL

Redirecting to API/Docs/index.html folder in Lumen

So i have an API created with Lumen with some documentation done with Apidoc outside of the public folder and i'd like to serve it when the user goes to the URL http://apidomain.com/docs
This is the structure of the app
ProjectRoot
->API
->Auth
->Docs
->v1
->app
->bootstrap
->database
->public
...
Is there any way to create a route that sends the user to API/Docs?
It's done, it was actually my bad, when trying to call the file via routes it actually messed up the filepath for the other files. So when i looked in the dev tools on chrome i noticed i was getting 404's on my js and css files, hence the failure to load the ApiDoc

Laravel routes with domains and subdomains

I've an app developed with laravel 5 and I will deploy it in a digitalocean droplet.
Can I have multiple domains and subdmanins in my server that using this unique application?
How I should implement routes.php to involve that?
I use this code to subdomains on 'mysite.com'
Route::group(array('domain' => '{subdomain}.mysite.com'), function() {
Route::get('customer/{customerId}', function() {
//blablabla;
});
});
But What I have to do if I have others domains like 'othersite.com'?
PS: All domains are hosted in the same droplet.
For subdomain, no problem (like said in http://laravel.com/docs/5.1/routing#route-group-sub-domain-routing)
For domain, you can, but with the url set in the config you'll have problem with link...
So, i'll do things like that :
Get the domaine name ( something like $request->server->get('SERVER_NAME') or request()->server->get('SERVER_NAME') )
update the config with \Config::set('app.url', $mydomainename)
You can do that in route, but maybe it will be better in a middleware.
And voila
Ps: take care about duplicate content with google, maybe some canonical will be usefull

Access controllers in sub directory

My controllers are at controllers/frontend directory I access them trough http://localhost/controller_name.
In a routes.php i have that record $route['([a-z_]+)'] = "frontend/$1" and everything works.
But how to change route rule if I want to access http://localhost/controller_name/method/param;
Your rule is sending everything to /frontend/$1 which is a silly idea.
If you have to do that, do this:
$route['(some_controller|other_controller)'] = '$1';
$route['(some_controller|other_controller)/(:any)'] = '$1/$2';
By doing it this way you are essentially destroying CodeIginter automatic routing, as you send EVERYTHING BUT certain controllers to the frontend. To learn how to build a Admin backend properly, try this article:
http://philsturgeon.co.uk/news/2009/07/Create-an-Admin-panel-with-CodeIgniter

Resources