I have installed a fresh copy of laravel 7.0 today and I am working with following routes and controllers
Routes
Route::get('/','DashboardController#dashboard');
Route::get('dashboard2','DashboardController#dashboard2');
Route::get('dashboard3','DashboardController#dashboard3');
DashboardController
class DashboardController extends Controller
{
public function dashboard(){
return view('dashboard.index');
}
public function dashboard2(){
return view('dashboard.index2');
}
public function dashboard3(){
return view('dashboard.index3');
}
}
All of these routes returns 404 not found except these one Route::get('/','DashboardController#dashboard');
Here I have discovered that the route having '/' url only works fine because if I change dashboard2 url to '/' it also works,
other routes are also working on Laravel Development server by php artisan serve command. But I am not used to do so, Is there any solution?
route list
+--------+----------+------------+------+-----------------------------------------------------+---------
---+
| | GET|HEAD | | | App\Http\Controllers\DashboardController#dashboard | web
|
| | GET|HEAD | dashboard2 | | App\Http\Controllers\DashboardController#dashboard2 | web
|
| | GET|HEAD | dashboard3 | | App\Http\Controllers\DashboardController#dashboard3 | web
|
+--------+----------+------------+------+-----------------------------------------------------+---------
---+
I already cleared all caches like route, view, config etc
add to your .htaccess RewriteBase / and copy this file to root, this solved my problems on a clean install WAMP+laravel 7
Just update your composer. 100% work even in CPANEL mode.
Related
i have a problem after trying to deploy my Laravel 9 application on AWS, my environment is healthy but still get this error when trying access to the site :
[ unexpected token ")" in public/index.php:51]
Error image
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Kernel::class);
//this is the error line 51
$response = $kernel->handle($request = Request::capture())->send();
$kernel->terminate($request, $response);
Using PHP 8.1.6
I want to deploy my laravel application on a shared webhost, I have follow this tutorial https://www.youtube.com/watch?v=6g8G3YQtQt4 and its works perfectly, only if I put the public folder in public_html, but I want to put in another folder in public_html, (to be more exactly, in: public_html/myapp, but I get this error
[15-Apr-2022 15:19:32 UTC] PHP Warning: require(/home/killestone/public_html/myapp/../web/vendor/autoload.php): failed to open stream: No such file or directory in /home/killestone/public_html/myapp/index.php on line 24
[15-Apr-2022 15:19:32 UTC] PHP Fatal error: require(): Failed opening required '/home/killestone/public_html/myapp/../web/vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php74/root/usr/share/pear') in /home/killestone/public_html/myapp/index.php on line 24
this is my index.php inside public_html/myapp
The rest of my laravel application is on /home/killestone/web/
<?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__.'/../web/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__.'/../web/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);
Because your public directory lives inside sub-folder inside the public_html
so you need to add an extra ../ because your public app lives in
public_html/myapp
so the first ../ will point to the public_html dir and the second ../ will point you to the home directory
like this
<?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__.'/../../web/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__.'/../../web/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);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm setting up e2e tests using Laravel Dusk and I'm having problems trying to figure out how to test Laravel's authentication.
I am migrating a database using DatabaseMigrations trait and populating it with 1 record ( running setUp method which mocks up a user ). I tried to login with this specific user using the loginAs() method but it doesn't log me in.
My AuthenticationTest.php file
use DatabaseMigrations;
public function setUp(): void
{
parent::setUp();
factory('App\User')->create();
}
public function an_authenticated_user_will_see_an_account_button()
{
$this->browse(function (Browser $browser) {
$browser
->loginAs(User::find(1))
->visit('http://recipemanager.test/recipes')
->assertSee('Account');
});
}
My dusk routes
| | GET|HEAD | _dusk/login/{userId}/{guard?} | | Laravel\Dusk\Http\Controllers\UserController#login | web |
| | GET|HEAD | _dusk/logout/{guard?} | | Laravel\Dusk\Http\Controllers\UserController#logout | web |
| | GET|HEAD | _dusk/user/{guard?} | | Laravel\Dusk\Http\Controllers\UserController#user | web |
Note that I haven't touched any controllers, files related to Laravel Dusk!
I am not using a testing database for my tests and I know that's bad I'm getting into it don't hate me.
Steps to reproduce the bug ( You need to have XAMPP ):
1. Clone the repo
2. Switch to branch account
2. Configure the .env file to match your database
3. Make sure to configure vhosts Apache file and etc/hosts file so you can access recipemanager.test as home route ( 127.0.0.1 recipemanager.test )
4. Run php artisan dusk
Errors:
1)Tests\Browser\AuthenticationTest::an_authenticated_user_will_see_an_account_button
Did not see expected text [Account] within element [body].
Failed asserting that false is true.
I fixed the problem by visiting recipes visit('/recipes'). The problem was in the environment file -> APP_URL was set to localhost and Dusk was trying to visit localhost:800/recipes. I checked that by asserting full URL
$this->browse(function (Browser $browser) {
$browser
->loginAs(User::find(1))
->visit('/recipes')
->assertUrlIs('http://recipemanager.test/recipes');
});
Error: Actual URL [http://localhost/recipes] does not equal expected URL [http://recipemanager.test/recipes].
.env file
APP_URL=http://localhost
After I changed the APP_URL to http://recipemanager.test and visit /recipes everything is working fine!
I'm trying to learn Laravel (5.3.28) and I'm running into an issue with my very first api route not working. I've followed the Laravel docs and can create a new project and can navigate to the Laravel splash screen indicating it's working. I added the following route to routes/api.php to test if I can consume the end-point, but I get an error:
routes/api.php
Route::get('foo', function () {
return 'Hello World';
});
error
NotFoundHttpException in RouteCollection.php line 161:
I have a dedicated CentOS box running XAMPP for my web server. the address to hit the end-point is http://10.0.0.200/test/api/public/foo.
I'm read that my .htaccess file should be edited, but the few examples I found match what I already have, so I'm a little lost on what to do.
Here is the output for php artisan route:list:
+--------+----------+----------+------+---------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+----------+------+---------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/foo | | Closure | api |
| | GET|HEAD | api/user | | Closure | api,auth:api |
+--------+----------+----------+------+---------+--------------+
10.0.0.200/test/api/public is the root URL I assume. If yes, then you need to hit 10.0.0.200/test/api/public/api/foo
I think that your project lies in the folder test/api, what you need is to reconfigure apache\nginx to route all requests going to 10.0.0.200/test/ , to start going to {webser root}/test/api/public . This is done in web server configuration files
Laravel uses the artisan commands to do several development tasks, such as running a built-in web server. You can do this by opening a new terminal inside the root directory of your project (where the artisan script is located) and run the following command :
php artisan serve
This should notice you with the URL of the built-in web server. You can then access it through your web browser. Generally, http://localhost:8000
This way, you'll be able to access your route which heads to http://localhost:8000/foo and in which you should find the page that says Hello world as your return in your closure.
I have install the Dingo with composer, and change the app.php file. After configure the app.php file, then i have publish vendor that, and get the api.php file.
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['namespace' => 'App\Http\Controllers'], function ($api) {
$api->get('users', 'EventsController#index');
});
Then i try php artisan api:routes
This is my result:
+----------------+----------------+------+---------+-----------+------------+----------+
| Host | URI | Name | Action | Protected | Version(s) | Scope(s) |
+----------------+----------------+------+---------+-----------+------------+----------+
| api.kayice.com | GET|HEAD users | | Closure | No | v1 | |
+----------------+----------------+------+---------+-----------+------------+----------+
Then i php artisan serve go to localhost:8000/user
It just show me this Sorry, the page you are looking for could not be found.
Could that anything is might miss for that?
Edited
I have added the provider in the app.php, i think after the vendor publish, the api working, then everythings should working. Or else is the laravel 5.2 problem?
I figure out what is the problem now, i didnt add the prefix in the api.php. Therefore it didnt return me the value.
Edited
But it still does not, most probably the system still no yet support well