Laravel 5.7 route exists, but shows 404 - laravel-5

I ran route:list and as you can see, the controller, and route is there.
| | POST | videos | | App\Http\Controllers\VideoController#store | web,auth |
And if I post to videos it gets 404. Its not the controller, because I tried returing just a string from the route.
I tried route:cache and cache:clear

Problem solved, it was a conflict with public folder. I downloaded a template which had videos folder, and so webserver tried to load that instead of sending it to Laravel.

Related

Error while running php artisan serve command on localhost

I am having issues with php artisan serve command. I am working on one Laravel project and when I access the folder from browser it is working fine but when I run the php artisan serve command it shows me the following error:
Warning:
require(E:\xampp\htdocs\www\LFS\public../vendor/autoload.php): failed
to open stream: No such file or directory in
E:\xampp\htdocs\www\LFS\public\index.php on line 24
Fatal error: require(): Failed opening required 'E:\xampp\htdocs\www\LFS\public../vendor/autoload.php'
(include_path='E:\xampp\php\PEAR') in
E:\xampp\htdocs\www\LFS\public\index.php on line 24
I am new to Laravel please let me know where I am going wrong.
I have checked the code in the public/index.php file below is my code. I guess everything is fine I just copy-paste the same index.php file on my root folder.
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
I want that the project can be directly accessible from the browser and should also run on the php artisan serve command.
In your project folder, the vendor folder is missing so you got this error:
Warning:
require(E:\xampp\htdocs\www\LFS\public../vendor/autoload.php): failed
to open stream: No such file or directory
Just run this command:
composer update --no-scripts
composer update
With this command, you will re-create the vendor folder in your project

Laravel Route exist in artisan route:list but not in route files

When I am checking php artisan route:list, the route which i want to redirect is listed there.
for ex: admins.dashboard.panel
but I didn't found any related route in route code files.
And I have code in my LoginController as
return redirect()->route('admins.dashboard.panel');
which is redirecting to login page again.

Laravel 5.6 - The requested resource /home was not found on this server

I am having a bit of an issue with one route (and only with this one, every other route works without any issue).
This are my routes (I commented out all routes, except the /home, just to be sure that they are not messing up something):
<?php
// Route::get('/', 'DashboardController#index')->middleware('menu.admin')->name('home');
Route::get('/home', 'DashboardController#index')->middleware('menu.admin')->name('home');
// Route::get('/user/verify/{token}', 'Auth\RegisterController#verifyUser');
// Route::get('logout', '\App\Http\Controllers\Auth\LoginController#logout');
// Auth::routes();
// // Admin routes (admin dashboard)
// require(base_path() . '/routes/admin.php');
// // Site routes (frontend)
// require(base_path() . '/routes/front.php');
I am getting this error:
Not Found
The requested resource /home was not found on this server.
The / route works without any issues, and when I try /home (the only difference between this two routes), I am getting the error.
I did php artisan route:clear, and it didn't help. Does anyone have an idea what is going on (.htaccess file is not an issue here)?
Laravel ^5.6
if your routes are defined properly, and by properly i mean you defineded routes in the right order (to avoid conflicts) and the artisan command php artisan route:list get executed correctly BUT you still get 404 Not found - The requested resource /path was not found on this server. weird, not exactly what you were expecting!!
...i also faced this problem, and here is the thing, that error occurs when you create a folder in the public directory with the same URI
...to illustrate here's an example (this is the problem i faced)
routes/web.php
/*
|--------------------------------------------------------------------------
| Web Routes - Backend
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Backend', 'prefix' => 'backend'], function () {
Route::get('/', 'DashboardController')->name('backend.dashboard');
// ...
});
php artisan route:list
php artisan route:list --name=backend --columns=uri --columns=name
+--------------------------------+--------------------------------------+
| URI | Name |
+--------------------------------+--------------------------------------+
| backend | backend.dashboard |
| // ... | // ... |
+--------------------------------+--------------------------------------+
public/
+---public
| +---backend
| | +---css
| | +---fonts
| | +---images
| | +---js
| +---.htaccess
| +---favicon.ico
| +---index.php
| +---mix-manifest.json
| +---robots.txt
As you can see, i have a route URI that start with backend AND also a folder under the public directory named backend as well, that's what cause the problem, so it's up to you to change one of those, personally i changed the name of the folder under public directory to "back-end". that solved my problem.
you use apache or nginx as web server?
try to set config for webserver
https://laravel.com/docs/5.6/installation
Because, you have a folder named control on /public folder. That error occurs when you create a folder in the public folder with the same name as your route so please change the name of the folder you have put in the public folder so that it has a different name from your route this will probably solve your error

laravel passport password grant Unauthenticated

I'm using 5.5 larevel's version and postman to test the API.
I ran the command
php artisan passport:client --password
To generate id and secret. When I post localhost:8000/oauth/token
post:
it returns me a token but when I want to get an enpoints values its returns me Unauthenticated
here is route api.php
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/users', function (Request $request) {
return $request->user();
});
Route::middleware('auth:api')->get('/subjects','SubjectController#index');
If you are in Apache server, I guess this should help you as it works on mine :
Just add these lines on your .htaccess file :
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
as stated in this thread.
Hope that helps.
Check valid access_token.
In my case, Error occur because I just copied a part of access_token.
Ex:
access_token: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImE2YWU0YjdjNjQzN2NhMjgxNTgxMGZhOGQ1ZmJmNDE5YzUwZDVhMzEyZmRiMzVmYTIyZjA0ZmZmMGQ0MDQxMzU2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Q1ZmJmNDE5YzUwZDVhMzEyZmRiMzVmYTIyZjA0ZmZmMGQ0MDQxMzU2M2E1YWIyMGM1ODE3ZDAwIn0

Laravel 5.4 php artisan route:list showing incorrect data after a route:clear

I have the following issue. I am running laravel 5.4 and have a problem with my routes, when I navigate to my '/about-me' of my predefined routes I get the error:
1/1 NotFoundHttpException in RouteCollection.php line 179:
However the route is defined as shows here:
Route::get('about-me', function () {
return view('about-me');
});
On my view the link is pointing to that route as shown:
About Me
I have cleared my cached routes in SSH using the command:
php artisan route:clear
When I list my routes using the command:
`php artisan route:list`
I see an old version of my routes file. So this is the problem, however whatever I try they are not updating. I have cleared the cache locally and within laravel and still the old file file is showing when I type the route:list command.
I believe the code is all correct, however the new updated route file which contains the defined route for about-me is not being used. I have attached an image of the updated routes file on the server also.
Here is a link to the screenshot. Screenshot of route file on server
Thanks
In Laravel 5.4 (or in earlier version, I'm not sure) routes has been moved to the separate folder in app/routes/web.php (as you can see here: https://github.com/laravel/laravel).
You can find routes registration in app/Providers/RouteServiceProvider.php (https://github.com/laravel/laravel/blob/master/app/Providers/RouteServiceProvider.php#L52)

Resources