I am using Luracast/Restler in my application, I want to prefix all the routes with api I tried using the $r->setBaseUrl("/api"). But when I am hitting the API it is throwing 404 exception.
Related
I just made a new installation of Codeigniter 4.2. It worked fine. Then, I copied the controllers, models and views from my existing project in Codeigniter 4.1.9.
The application loads fine. When the application makes post submit, it always shows 404 - File not found.
I have set the routes->setAutoRoute(true); in Routes.php and Set $autoRoutesImproved to true in `app/Config/Feature.php.
Still getting the same error.
Since v4.2.0, Auto-Routing has been disabled by default. Because it is easy to create vulnerable apps where controller filters or CSRF protection are bypassed.
But if you want to run v4.1.9 apps, you need to set $routes->setAutoRoute(true) in Routes.php and set $autoRoutesImproved to false in app/Config/Feature.php.
I have made a basic Laravel project and had configured my api.php file to have a GET route when I want to fetch data for my project, but whenever I try to load the data on browser or perform a GET on the link (localhost:8000/data) from postman, it shows Error 404 Not Found. It seems that the GET is not able to find the URL that I had mentioned above. How can I get this issue sorted?
Not 100% sure this applies to you from the question. But Laravel prepends /api/ to API routes by default.
Maybe try requesting from localhost:8000/api/data?
i'm having an issue with laravel routing, i'm getting 404 HTTP errors when i try to access a specific route.
This is my routing config:
/** Api First Version Routes */
Route::prefix('v1')->group(function(){
// Auth Routes
Route::post('register', 'Api\AuthController#register')->name('register');
Route::post('login', 'Api\AuthController#login')->name('login');
});
My route seems to be accessible on artisan route list command output
but when i try to access through my SPA HTTP Client, it returns a not found http error, image below.
and this error just happens when i try to access the login route.
EDIT***
When i remove the route from the prefix group, it works fine, seems that the problem is just when i'm using routing prefix.
after many hours trying i have solved this problem, i tried to remember what modifications i did in my code before getting errors, so i remembered that i removed the code Passport::routes(); from my App\Providers\AuthServiceProvider.php file.
After adding it back to my AuthServiceProvider.php file all stuff worked again.
My app/config/app.php has
'url' => 'http://dev.domain.com/something/somethingElse'
Then I have a function that can be called from the application and also from an artisan command. But URL::route('myRoute') returns different results. When called from the application it returns http://dev.domain.com/something/somethingElse/myRoute, but in the artisan command http://dev.domain.com/myRoute.
URL::to has same behaviour.
Note: I do not have any other app.php file defined for other environments that could overwrite the global one.
Any ideas why this happens ?
Thanks!
A Laravel-generated URL consists of a number of parts:
Scheme: http://, https://, etc.
Host: dev.domain.com, localhost, etc.
Base: something/somethingElse (the subdirectory on the web server)
Tail: myRoute, (the Laravel route parameters)
These parts are then concatenated to form the URL.
Ultimately, Laravel generates the URL using the $_SERVER request variables. The function prepareBaseUrl() in Symfony\Component\HttpFoundation\Request is what is ultimately used to determine the base part of the URL.
When you make a request through your web browser, the request goes to ~/public/index.php and the necessary $_SERVER variables are populated with the correct information for Laravel to populate the base part of the URL.
However, when you make the request using Artisan on the command line, the request goes to the ~/artisan script. This means that the $_SERVER variables are not populated in the same way and Laravel is not able to determine the base part of the URL; instead, it returns an empty string ''.
From what I can find, it doesn't look like there is any appetite from the Laravel team to enable the application to function out-of-the-box in a subdirectory, e.g. Bugfix: domain routing for subfolder.
I ended up working around it in the way described by #medowlock for my scripts that would be called from the command line, e.g.:
Config::get('app.url') . URL::route('route.name', ['parameter'=>'value'], false)
This concatenates the application URL set in the app/config/app.php and the relative URL route.
If you use Laravel 4.2, you can call the URL::forceRootUrl function to explicitly define what the root url of your laravel application is.
URL::forceRootUrl( Config::get('app.url') );
Calls to URL::to will use the URL define in your app config file after forcing the Root URL.
Unfortunately, this isn't available in Laravel 4.1 or Laravel 4.0
I have a problem with Laravel/Angular AJAX integration :
I can directly go into my laravel routing by putting it on my own but Angular AJAX doesn't work. This is what I get from my browser console :
GET path to my laravel route (Not Found) angular.js:8611