I got this exception for this route: http://localhost:8000/ and other route that I wrote in routes.php file and when I wrote
php artisan route:list
I got this message
Your application doesn't have any routes.
I didn't change anything in my code and it worked successfully.I searched about it but I couldn't find an exact answer why this problem happened.
this is routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
$name = ['saba','safavi'];
return view('welcome'/*,compact('name')*/);
});
Route::get('/sabasafavi', function () {
return "Salam saba safavi";
});
Route::get('/contact-us', function () {
return view("contact-us");
});
\Illuminate\Support\Facades\Route::get('/user/{id}',function ($id){
return "hello user : ".$id;
})/*->where(['id'=>'[0-5]+'])*/;
\Illuminate\Support\Facades\Route::get('/user/{name}/comment/{number}',function ($name,$number){
$comment = "Hello ".$name." this is your comment</br> number : ".$number;
return $comment;
});
/*Route::post('/send',function (){
return "OK information saved successfully";
});*/
First make sure your web.php is being loaded on RouteServiceProvider.php
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
or it might be that your old empty web.php it has been cached since you have cache enabled so do : php artisan route:clear then run php artisan route:list
this problem is because of renaming your Laravel applications.
If you are using an IDE like PHPStorm or sublime do a full search (find in files) (Edit->Find->Find in Path) of laravel5learning across all files in your project directory and all sub-directories and then change it to App
then run php artisan route:list
Please try
php artisan serve
this command and this will give you something like this http://127.0.0.1:8000. So that in localhost you just add this and then your route like -
http://127.0.0.1:8000/
here'/' is your default route i used/
hope will work for you
Related
I was facing the issue when I do php artisan optimize.
Below is my api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
/* |-------------------------------------------------------------------------- | 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('/user', function (Request $request) {
return $request->user();
});
I am confuse & don't know what I am missing.
Already tried following options
Delete all cache files
Also tried php artisan cache:clear
Composer update / composer dump-autoload
env file changes CACHE_DRIVER=file,SESSION_DRIVER=database
Thanks in advance .
If you check Laravel's optimize command:
/**
* Execute the console command.
*
* #return void
*/
public function handle()
{
$this->call('config:cache');
$this->call('route:cache');
$this->info('Files cached successfully!');
}
There is a line $this->call('route:cache');
This line is throwing the error.
Laravel is trying to cache the routes. It does not accept Closure while caching the route. That's why moving your code to a controller fixed the issue.
So I've cloned my own laravel project, that works on my main machine, to my test pc and set it up as follows:
Installed XAMPP and set it up.
git clone project to the machine.
Installed composer on the machine.
executed the command composer install.
php artisan key:generate.
I installed Postgres and set up a DB
uncommented Postgres extensions in php.ini
Edited the .env file to connect to the DB
php artisan migrate:fresh.
php artisan db:seed. (New users)
Now when trying to log in, the page just refreshes. I found out that I'm able to read and write to the database when creating a new page that is not protected by the login.
So something with the whole auth situation must be wrong. Did I miss anything when setting the whole project up? Or where the commands executed in the wrong order?
Oh btw. The auth was made with php artisan make:auth
Here is part of my web.php. The whole thing is really big.
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index');
Route::get('/user', 'UsersController#index')->middleware(['auth.admin']);
Route::post('/user', 'UsersController#store')->middleware(['auth.admin']);
Route::get('/user/edit/{id}', 'UsersController#edit')->middleware(['auth.admin']);
Route::post('/user/update/{id}', 'UsersController#update')->middleware(['auth.admin']);
Route::get('/user/delete/{id}', 'UsersController#delete')->middleware(['auth.admin']);
Route::get('/usersearch', 'UsersController#search');
Route::get('/user/paginate/{id}', 'UsersController#paginate')->middleware(['auth.admin']);
Route::get('/order', 'OrderItemController#index');
Route::get('/order/delete/{id}', 'OrderItemController#delete');
Route::get('/order/edit/{id}', 'OrderItemController#edit');
Route::post('/order/update/{id}', 'OrderItemController#update');
Route::post('/order', 'OrderItemController#store');
Route::get('/ordersearch', 'OrderItemController#search');
Route::get('/order/paginate/{id}', 'OrderItemController#paginate');
Route::get('/customer/delete/{id}', 'CustomerController#delete');
Route::get('/customer/edit/{id}', 'CustomerController#edit');
Route::post('/customer/update/{id}', 'CustomerController#update');
Route::get('/customer', 'CustomerController#index');
Route::post('/customer', 'CustomerController#store');
Route::get('/customer/paginate/{id}', 'CustomerController#paginate');
Please check your current laravel version.
php artisan make:auth command is not longer available from Laravel 6.X
I have just installed laravel 5.7. So, In web.php I have defined Route.. Like
Route::get('foo', function () {
return 'Hello World';
});
But when i Hit the URL -> http://localhost/rp/public/foo
It shows me 404 page not found.
use PHP's built-in development server, you may use the serve Artisan command:php artisan serve
Later you can check in browser like this: http://localhost:8000/foo
If you have to check without artisan serve
Route::get('/foo', function () {
return 'Hello World';
});
you can check like this(rp is your laravel-project-name): http://localhost/rp/public/foo
you must have a configuration like this in your .htaccess file
My laravel project is showing this error: NotFoundHttpException in RouteCollection.php when i am trying to sync my project to github using github desktop, except for this route:
Route::get('/', function () {
return view('welcome');
});
but another simple route like following will not work, and return that error.
Route::get('loa', function () {
return view('loa');
});
In route list, using route command: php artisan route:list it says it exists. but it always returns Route not found. I also have tried to use the command dump-auto load or route:clear, but nothing is working.
Run composer update then try again.
I 'm new to LARAVEL 5 ,so i have created about.blade.php in ~/project/resources/views and then add this code in app/routes.php in order to view the page when requested in browser:
Route::get('about', function () {
return view('about');
});
========================================================================
Then i requested in browser as this : http://localhost:8000/about .
so this error is shown in browser :
[
I solved this issue using sudo command with php artisan serve
It was Permission issue .