I have just deployed Laravel 5.4 using Composer on a shared hosting and I've run into several problems which I think are now fixed.
The first one was folder permissions which is now fixed so at least I see a welcome page.
I noticed that composer install never create a routes directory so I uploaded a local version and also it never creates a cache directory in the boostrap folder which I fixed also.
I have installed Laravel on a subdomain and I want everything to run through the subdomain as the root folder has a different application.
If i got to the subdomain, the welcome page opens as expected but as soon as I try to use a different route, I get this error:
NotFoundHttpException in RouteCollection.php line 145:
I have looked at what other people have done with subdomains but nothing works for me. I don't know if there are other files are missing during the install
This is what I have in the Routes.php
Route::group(['domain' => 'subdomain.example.com'], function () {
Route::get('/', function () {
return view('welcome');
});
Route::get('test', function () {
return view('welcome');
});
});
I assume every route needs to run in the subdomain route group or do I need to use this at all seeing as the install is in the subdomain directory and the vhost is pointing to the subdomain public folder
It turned out to be a problem with the PHP version the command line was using on Plesk.
Currently Plesk runs in 5.4 and Laravel needed 5.6. For some reason Composer ran successfully and it seemed to miss downloading some of the files.
I wiped everything from the subdomain and thanks to this http://blogs.reliablepenguin.com/2015/08/18/using-php-composer-phar-with-non-default-php-install i was able to run composer using php version 5.6
I didn't need any special route for subdomains as everything is in the subdomain and these routes worked as expected
Route::get('/', function () {
return view('welcome');
});
Route::get('test', function () {
return view('welcome');
});
Related
I am creating an application to be hosted on a server, and I used .htaccess however the first page that load which is usually the login screen(whose path is in my resources folder)has change to the public folder and I click anywhere else as everything is linking to the public folder, which is not right as its supposed to be in the resources folder... the app works fine, its just the routing that's giving me an issue so when i click anywhere else it says, 'the requested url can not be found on server'
I also tried putting the view folder into the public folder and routing there
my homepage is set to:
Route::get('/', function () {
return view('auth/login');
});
but this gets an error when moved to the public folder, the error reads,
InvalidArgumentException
View [auth.login] not found.
Clear your caches and restart your server:
composer dump-autoload;
//---Flush the application cache
php artisan cache:clear;
//---Remove the configuration cache file
php artisan config:cache;
php artisan config:clear;
//---Remove Routes Cache
php artisan route:clear;
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 am having a problem with accessing the Auth::user() in a Laravel package routes file.
I am creating a package for Laravel (using 5.8.9). The package has its own routes in a route file which is being added correctly.
I have created an identical route in the main test site and the package. I am using composer 'path' to symlink the package into the test site which is on Homestead that I'm using on a windows 10 computer.
The route is simple and I'm just checking to see if a user is logged in, which it is.
Route::get('/home', function () {
dd(Auth::check());
});
In the main site routes file the check is returning true as expected. When commented out and allowing the route file in the package to handle it we get a return of false.
I noticed it as was getting an error when trying to run middleware on the package and after some investigating found that the package is not registering the user as being logged in.
Any ideas? Is it a problem because I'm using the path on composer to symlink?
EDIT: OK I've ruled out the symlink being the problem by creating a private repo and importing it. So its now in the vendor as a normal imported package but still getting the same issue.
EDIT2: I just tried to pull a user in the package routes file by just doing a simple
Route::get('/home', function () {
$user = \App\User::find(1);
dd($user);
});
And get null does anyone know if its possible to access the user/core laravel models in a package or is it disabled or a problem with the load order?
I managed to resolve it, if you use routes that require auth in your packages then you need to include the web middleware. If you do not include the web middleware then you are not loading some of the functionality that the main framework will load, like sessions.
And if you don't have sessions then obviously you wont be able to retrieve logged in users.
So to get it working you would change the code to
Route::get('/home', function () {
$user = \App\User::find(1);
dd($user);
})->middleware(['web']);
I am using Ubuntu 16.04 and installed Laravel 5.3 on desktop/Laravel/test directory. I have created a test.blade.php file in resources/view directory. I have also created routes.php in app/Http directory and added following code:
Route::get('/', function(){
return view('test');
});
When I enter command in terminal: php artisan serve and go to http://localhost:8000 url in browser, it shows default page of laravel after installation. Why it is not showing view I have created? I have also tried writing following code in routes.php:
Route::get('/', function(){
echo "Test";
})
But still it doesn't work. Is there anything I am missing?
Reference
By default, fresh Laravel 5.3 applications contain two HTTP route
files in a new top-level routes directory. The web and api route files
provide more explicit guidance in how to split the routes for your web
interface and your API.
The routes.php is moved to different folder in Laravel 5.3. Update routes/web.php file.
From the Laravel Documentation 5.3
The routes directory contains all of the route definitions for your application. By default, three route files are included with Laravel: web.php, api.php, and console.php.
The routes.php was there in previous version. But in laravel 5.3 the routes.php is moved to routes/web.php as Saumini Navaratnam said.
I have just set up a new laravel 4 project and I can't seem to get my routes to work.
I have the following code in my routes.php file.
Route::get('test', function()
{
return 'test';
});
Route::get('/', function()
{
return View::make('hello');
});
But if I go to localhost:8888/laravel4 I get a directory listing instead of the '/' route.
If I go to localhost:8888/laravel4/test I get The requested URL /laravel4/test was not found on this server.
I am using MAMP with php 5.5.3 for my localhost.
The entry point is in the public directory
So you go to
localhost:8888/laravel4/public/
to get the / route
and
localhost:8888/laravel4/public/test
to the test route.
Otherwise, you should set up a vhost (Don't know how to do in Mac) and point it to the public directory of your laravel project