Laravel localhost API Error 404 While /public is working - laravel

Hi This is my 2nd Post here.... I been searching over the internet for almost 12 hours and so far nothing can help me so i decide to post here. I just finish my CMS and i would like to start my API and ......
My Problem is my API route is not working properly :
My Postman ScreenShot
But When I am running my other file in CMS is working :
My Brower Localhost CMS Screenshot
My Route :
Route::group(['prefix' => '/v1' ,'namespace' => 'V1', 'middleware' => 'JsonApiMiddleware'], function(){
Route::post('/login', 'UserController#login');
My Folder and File Location :
My API Location and Folder

Hi I manage to solve it after talking to many people and learn about the PHP ARTISAN SERVE....
The Actual Path for the postman to work is : http://127.0.0.1:8000/api/v1/login
and you need to type "php artisan serve" in your command line in your laravel folder to start web server for laravel. Then my API is working perfectly. Coz the CMS is already handle by the Xampp but the API cannot run on Xampp based on my PC configuration.

Related

How to access laravel api from vuejs frontend?

I have built a laravel api, I have placed the backend inside a laravel folder in the cpanel and the built vuejs frontend inside public_html, now u can see I am using both api.php and web.php, my frontend is working fine when I visit https://www.example.com but what's the url to my api endpoints since when I try something like https://www.example.com/api/somepage it doesn't work it just hits the routes I set using vue router?
Please I need help here I am a beginner, and thanks in advance.
Laravel apis have default middleware to establish security. Make sure you send tokens. In my opinion, test it in postman first.
If you have a 404 error , this link can help you
Sometimes it is possible that there is a problem with the route cache, so it is better to delete the route cache and create it again
php artisan route:clear
php artisan route:cache

Laravel sanctum problem when deployed to Heroku

Hello guys I've been trying to build a full-stack web app, and everything was working fine on my localhost using postman. But after uploading to Heroku, it would seem I have a problem with sanctum. It keeps throwing this error:
Things I've tried:
Run composer update
php artisan cache:clear
Trying to add sanctum with composer require laravel/sanctum.
Following sanctums installation guide with all steps on the Laravel home page
And this is inside my api.php where I guess the initial error starts.
Route::middleware('auth:sanctum')->group(function () {
// User Routes
Route::get('profile', [UserController::class, 'profile']);
Route::get('logout', [UserController::class, 'logout']);
});
I've been at it the whole weekend but I can't seem to crack this one, Also apologies in advance I have classes soon, so responding back will be slow.

I can not create new Routes in Laravel project

I was developing a Full-Stack Laravel project using livewire and tailwind CSS in the front, everything was working just fine, I even did 5 commits on GitHub on this project. The problem is I came back to continue developing the project, and when I create new routes, Laravel returns 404 PAGE NOT FOUND, I even tried to test a very simple route, and it did not work too(404 page not found)
Route::get('/test', function () {
return 'hi';
});
Any solution to this weird problem?
Might be a chaching problem.
Try clear your cache by running
php artisan cache:clear
php artisan clear
You can also check all registered routes by running
php artisan route:list.
If thats not working it could also be a problem with the browsers internal cache. Had something like this before with Firefox.
Try using curl to access the endpoint
curl http://localhost:8080/test

Laravel not working on remote server only test echo working

I am newbie to Laravel and first time setup the laravel app on remote server, I install laravel and configure with domain name by apache config but I am getting blank page on hitting url, For test I just echo test on public/index.php and its showing correctly but welcome page doesn't work, I don't know where I am making mistake.
This is fresh laravel app I have install directly on server
The question was vague.
Have you configure the route.php to your view welcome.blade.php

Laravel directory to welcome page on a VPS

Before I was in a shared hosting and had no problem installing and accessing (click next next), Laravel welcome page but I have moved to a bare metal VPS and I am having difficulties to get to the Laravel 5 welcome page. My host tells me to upload the framework to the htdocs directory, but that is exactly what I did and where the app et al are found.
This is the URL scenario.
My web VPS by default shows me its own index.html like this
/var/www/virtual/myweb.com/htdocs/index.html
and yes, I can correctly access that index through myweb.com
but, of course, all my views are in their Views folder, like this:
/var/www/virtual/myweb.com/htdocs/resources/views/welcome.blade.php
my routes page (as it is a freshly installed) naturally
Route::get('/', function() {
return view('welcome');
});
and the URL in my config/app.php file
'url' = >env('APP_URL', http://myweb.com');
If I do something like this in the URL browser box of course, I get to the file of Laravel 5 welcome page
http://www.myweb.com/resources/views/welcome.blade.php
but obviously I don't want to show such path
so, I would like to be able to write myweb.com and directly show my welcome.blade.php
Any ideas as to how?
You should point you web server (Apache) to a public directory of Laravel's project. For example:
DocumentRoot "/var/www/virtual/myweb.com/public/"
<Directory "/var/www/virtual/myweb.com/public/">
After rebooting web server normal URLs should work (if you'll set up correct settings).

Resources