i've been stumped by thhis one for a couple of days now. I get this error when i try loading the main page, I get the error in the title. I've asked this question here and tried putting dd() at the top of the page as well as running php artisan route:clear as well as other commands hoping I can get the home page to load. The funny thing is I can load the user login function no problem.
Here's my routes file:
<?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 () {
return view('pages.home');
});
Route::auth();
View Structure:
I found my problem. I didnt notice this before, but my project in PhpStorm was being saved to a directory outside my VM. i apologize for not figuring this out earlier.
Related
What is the proper way to add a subdomain into your routes? I have a laravel/homestead project working on my local computer but when I move it to HostGator, a shared host server, it no longer works. Well the home page works but the links to the sub-pages don't.
For example, the following route works fine on my local version:
Route::get('/appointments', 'AppointmentController#index');
But if I use that route on the remote server, it takes it to tekknow.net/appointments instead of tekknow.net/medaverter/appointments.
So I followed instructions from here:
https://laravel.com/docs/5.6/routing#route-group-sub-domain-routing
and added a prefix like this:
Route::prefix('MedAverter')->group(function() {
Route::get('/appointments', 'AppointmentController#index');
});
But that doesn't work either. It also goes to /tekknow.net/appointments
I also tried changing the route to this:
Route::get('/MedAverter/appointments', 'AppointmentController#index');
But that also went to tekknow.net/appointments
Anybody know what I'm doing wrong?
EDIT: I went onto my HostGator cPanel and looked at all my subdomains and saw that my subdomain root was medaverter.tekknow.net which is linked to Document root of medaverter.tekknow.net/MedAverter which gets redirected to http://www.tekknow.net/MedAverter. So I renamed my folder from medaverter to MedAverter to match the subdomain redirection.
Here is a screenshot showing what I see in cPanel for columns Subdomains.Root Domain, Document Root, and Redirection
When you try php artisan route:list | grep appointments,
it prints:
[~/www/MedAverter]# php artisan route:list | grep appointments
| | GET|HEAD | MedAverter/appointments | | App\Http\Controllers\AppointmentController#index | web |
That means your route MedAverter/appointments is working for laravel.
Error 404 means route cannot be found.
So I think that's something wrong with your nginx configuration.
When I try http://tekknow.net/MedAverter/MedAverter/appointments.
It has really found the route with error 500.
So, I think you have defined this code in your nginx configuration:
location = / {
rewrite ^ https://tekknow.net/MedAverter;
}
Solution 1:
Change back to rewrite ^ https://tekknow.net/; in nginx configuration.
(I'm not familiar with hostGatar cPanel, but I think you can change medaverter.tekknow.net/MedAverter redirected to http://www.tekknow.net/`)
And in your laravel project, you need to keep prefix MedAverter to appointments.
Solution 2:
Keep the rewrite code. It means you don't need to change the cPanel redirect.
And remove prefix MedAverter in laravel routes. HostGatar(Nginx) will automatically redirect with this prefix MedAverter for appointments.
Clear all caches
The problem you're getting can be due to cache. So, make sure that's not the problem by running
php artisan route:clear && php artisan view:clear && php artisan config:clear && php artisan cache:clear && php artisan clear-compiled
Base URL
If you want to change the base URL of your Laravel app, that's something already asked.
Multiple Path Prefixes
In this case you have a more than one route with the same prefix in their path. If that's the case, you can use route groups to simplify the structure.
Route::prefix('medaverter')->group(function () {
Route::get('/', function () {
// Path /medaverter
});
Route::get('appointments', function () {
// Path /medaverter/appointments
});
});
This would go to, respectively, tekknow.net/medaverter and tekknow.net/medaverter/appointments. You could also create another prefix, like testing, configure in the same way and go to tekknow.net/testing or tekknow.net/testing/whatever.
Namespace prefixes
When you’re grouping routes by route prefix, it’s likely their controllers have a similar PHP namespace. In the medaverter example, all of the medaverter routes’ controllers might be under a Medaverter namespace.
Route::namespace('Medaverter')->group(function () {
// App\Http\Controllers\Medaverter\AppointmentController
Route::get('medaverter/appointments', 'AppointmentController#index');
});
u can use route groups for that here is a sample try this:
Route::group(['prefix' => 'medaverter'], function () {
Route::get('/appointments', [AppointmentController::class, 'index'])->name('index');
});
or
Route::group(['prefix' => 'medaverter'], function () {
Route::get('/appointments', 'AppointmentController#index');
});
i'm trying to build a hyperlink from index.blade.php to login.blade.php by route. i defined a named route for this hyperlink but is not working.
here is my route code.
Route::get('/','HomeController#index');
Route::get('/login', 'HomeController#login_page')->name('login');
and here is my controller.
public function login_page()
{
return view('login');
}
and here is my view where i'm trying to set a hyperlink.
<li>Log-in</li>
Set URL link in a menu link using Laravel blade template, use it {{url('dashboard')}}. Use this link in the for example:
<ul>
<li>
Dashboard
</li>
</ul>
I think it will be helpful for you.
Your error message points to a server problem, not Laravel.
Make sure you'r mod_rewrite for apache is installed and enabled.
a2enmod rewrite
service apache2 restart
Then check your Laravel with:
In your console, run: php artisan route:list and see if you have a row similar to:
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------+---------------+---------------------------------------------------+-----------------------------+
| | GET|HEAD | login | login | App\Http\Controllers\HomeController#login_page | web,guest |
If you do not see the login part, try clearing route's cache with:
php artisan route:clear
Other than that, you are doing everything properly.
I had the same problem (Ubuntu 18.04), it does not seem to be Laravel but Apache.
Workaround: Install Xampp and use it as Localhost.
I'm new to laravel and have just created a project(laravel version 5.4.34).
After using:
composer create-project Laravel/Laravel project
and after adding the details for a mysql database connection and running
php artisan make:auth
I browse to the url of the project and get the basic laravel homepage, with the login and register links in the top left.
When i click either the register or the login link, it seems to get stuck in a redirect loop. How would this happen just after installation - would this be a routing problem?
UPDATE after Taylor Foster's comment
app/Http/Controllers/Auth/LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
routes/web.php
<?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')->name('home');
I think those are the locations of files. Do I need to add routes for /login and /register myself?
I'm not sure if this is useful, though I have been watching the second beginner laracast and follow instructions on making a new route, and that URL doesn't work either, I add:
Route::get('/about', function () {
return view('about');
});
to the routes/web.php
and create a basic page showing a h1 tag saying About, and save it at resources/views/about.blade.php as instructed.
This could be the same issue with the auth problem? I don't get why a standard installation of laravel's routes would simply not work - and ideas/advice would be greatly appreciated.
In case anyone had the same problem as I did when starting out with Laravel, adding:
<Directory "/var/www/project/public">
AllowOverride all
</Directory>
within the virtualhost config seems to have solved the problem.
In your Controllers, there should be Auth/LoginController.php. There should be a variable in there protected $redirectTo. Just set that to a registered route and see if you are still having the same problem.
It seems like a permission error, try setting the right permission on your project's directory.
sudo chown -R :www-data path/to/your_project
After, cd path/to/your_project and run this command so set storage's folder permission:
sudo chmod -R 775 storage
I'm trying upgrade my laravel project from 5.2 to 5.3.
Since laravel 5.3, the route files are kept in a separate directory routes, instead of the previous app\Http directory. I created the file routes/web.app and pasted my routes into this file.
When i execute php artisan route:list, it returns:
+--------+----------+-------------------+------+--------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------+------+--------------------------------------------+------------+
| | GET|HEAD | captcha/{config?} | | \Mews\Captcha\CaptchaController#getCaptcha | web |
+--------+----------+-------------------+------+--------------------------------------------+------------+
My routes/web.php file:
<?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(){
echo 'here';
});
Where is my route?
When I access the home page, it returns a 404 error, but the error comes from laravel.
The file .htaccess is ok.
You said:
I created the file routes/web.app and past my routes on file.
In Laravel 5.3 the web.php file is already created in the routes directory. If you have recreated this file that is where the problem may be propagating from.
I read the upgrade documentation and thought I needed to remove the EventServiceProvider, RouteServiceProvider, AuthServiceProvider methods from the boot ....
But in fact I needed to update the contents of these files.
After updating the contents to the new version 5.3 up to where I tested, it is working ....
I need some advice, i have just installed a fresh 5.2.37 version of Laravel.
Straight after the installation i setup the DB details in the .env file and then ran
php artisan make:auth
and then
php artisan migrate
Everything worked fine with no errors at all, when i view the index page of my site, i see the new landing page, but every time i click login or register it just returns 404's
There doesnt seem to be any login or register routes created, this is my routes.php file
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Route::get('/home', 'HomeController#index');
There is an AuthController.php in the auth directory, but there is also no mention of a login or register route.
Have i missed a step?
Any help would be great.
Peace!
Run php artisan route:list command. You should see these routes:
login | ...\AuthController#showLoginForm
login | ...\AuthController#login
logout | ...\AuthController#logout
password/email | ...\PasswordController#sendResetLinkEmail
password/reset | ...\PasswordController#reset
password/reset/{token?} | ...\PasswordController#showResetForm
register | ...\AuthController#showRegistrationForm
register | ...\AuthController#register
If you see these commands, auth is work.
So, just go to http://you.app/register for example and you'll see registration form.
By default you can not the see the routes in your routes.php file.
As it returns 404 page , can you please check , site/index.php/register ?
Once you run the command , you should have an automated view in your app root directory.
From the navigation menu , you should be able to see the buttons to login and register.
Also you can check your database whether the table was created or not.
It turns out when installing the brand new Ubuntu Server box, i forgot to setup mod-rewrite.
I have just gone through and it all works perfect now.
Sorry for any inconvenience.
Peace!