After share website on server, only mainpage works - laravel

I have a website and when I share it on trial server everything was ok. After I bought the domain so I must upload everything files again. Problem is that routung doesn't work correctly. I see only main page and whe I try open other page I see error 404. Chmod I change to 777 (public_html and folder with other files).
For example:
//This works
Route::get('/', [
'uses' => 'FrontendController#rules',
'as' => 'en.rules'
]);
//This doesn't work
Route::get('/rules', [
'uses' => 'FrontendController#rules',
'as' => 'en.rules'
]);
I found this https://laracasts.com/discuss/channels/laravel/laravel-5-only-home-page-route-working-on-live-server but it doesn't work too. Any idea?

Please make sure that you have published the providers and tag files if using third-party modules.
php artisan vendor:publish

Related

Laravel keeps logging me out after login

I have Laravel set up. I am running multiple domains to it. Before yesterday I had one top level domain and a few sub domains. I added another TLD yesterday and everything started working weird. Specifically, when trying to log into the admin section it redirects to the home page. I have one admin but server domains coming to the site. My route group it:
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function() {
Sometimes is actually brings me into the admin but as soon as I click on a link I get logged out and redirected to the home page. I keep seeing 401 errors in the console as well.
What would cause this?
edit
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function() {
Route::get('/', 'AdminController#index');
Route::get('/pages', 'AdminController#pages');
Route::get('page/create', 'AdminController#createPagePage');
Route::post('createPage', 'AdminController#createPage');
Route::get('/page/edit/{page_id}', 'AdminController#editPagePage');
Route::post('editPage', 'AdminController#editPage');
});
$redirectTo = '/';
If you are using Linux, try to check the session file permissions and change them so the app can write session keys on that file and if it doesn't work, try to change the session driver to database.
how to change the session driver?
Go to your .env file and change SESSION_DRIVER=file to SESSION_DRIVER=database.
create a session migration: php artisan session:table.
composer dump-autoload.
Finally migrate (php artisan migrate).
Have you setting the SESSION_DOMAIN right?
One thing you may notice is that session isn’t saved when the user is logged-in in one store and goes to another. To fix that issue, we’ll need to add a SESSION_DOMAIN variable to our .env file, for example:
SESSION_DOMAIN=’.example.com’
That’s all, now user session will be shared across all shops/subdomains in our app.
https://medium.com/#maxkostinevich/how-to-build-multi-domain-laravel-application-e6d87d5e507b
If you are confident with the domain setup correctly. Please verify these few things.
1. Your config/session.php is correctly setup to support multiple domains.
'driver' => env('SESSION_DRIVER', 'file'), // check /storage folder writtable recursivelly.
'domain' => env('SESSION_DOMAIN', null), // verify if single domain is not given in .env or in settings.
'same_site' => null // it should not be strict if you have ajax request across these domain. I mean from javascript you may try to request to other domain.
etc...
2. Confirm, if your routes are not group under domain specific. something like:
Route::group(['domain' => 'xxx'], function($params)
{
// your routes..
});
3. If there is any hardcoded domain verification/conditions or redirection added in code.
4. Any values in .env poiting to single domain.
5. Also don't forgot to clear the cache/compiled view/routes and delete the temp files once. like generated files inside /app/bootstrap & /storage
// Clear Application Cache
php artisan cache:clear
// Clear route cache
php artisan route:cache
// Clear config cache
php artisan config:cache
// Clear compiled view files
php artisan view:clear
6. Any thirdparty package might contains the domain settings. Make sure to verify the files in your /config folder.
7. Check the url rewrite settings in .htaccess
8. Do confirm if there is any proxy settings are there or any software installed on server - very rare case.
In case still having issue, please restart the apache/nginx service once because sometimes the config changes not effected after change that might need server restart.
Hopefully it helps.

Laravel 5.5 Route groups

I was having this in my website using Laravel 5.3 :
Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware'=>'auth'], function(){
Route::resource('posts', 'PostsController');
});
This lets me go to the admin panel using: mywebsite/public/admin/posts.
Now, when I migrated the site to Laravel5.5 I got this error Route[admin.posts.create] not defined when i attempt to open the link Create post which was working fine before.
I know that routing system has changed but I did not know how to have such links in new Laravel5.5. I tried url instead of route but I got the same error. I also checked the new documentation but I did not get exactly how to have the same link system.
Can anyone have a better explanation of this new routing system? (I have to migrate the site to 5.5).
Laravel names resource routes by default, you can check them by running php artisan route:list
If you want to override them for any reason you can pass in an array when you define the route and override each individual route name like so:
Route::resource('posts', 'PostsController', ['names' => [
'create' => 'admin.posts.build'
]]);

Laravel 5.3 NotFoundHttpException

I'm trying to setup a Laravel 5.3 project. I have create the project and starting the 'localhost//public' shows the welcome screen just fine.
When adding a test entry in the web.php file like
Route::get('about', function () {
return view('welcome');
});
An then trying to access this as 'localhost//public/about' I get this NotFoundHttpException in RouteCollection.php line 161: error. I'm really puzzled as to whats wrong.
In the 5.2 version, with the routes.php, it worked perfectly fine.
Regs.,
Erik
NotFoundHttpException means Laravel can't found the requested route. Hence, you are trying to access something which doesn't exist that's why it is throwing NotFoundHttpException.
Try to access your route like
localhost/public/about
Well its a strange story when using artisan route:list the about neatly pops up. However when accessing through Chrome i wasn't able to load it. I have dropped the whole www directory and started afresh. Now it works. Must have been something lingering around.
Thx.,
Erik
You can try adding a 'public' prefix for the web routes in app\Providers\RouteServiceProvider.php like so:
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
'prefix' => 'public',
], function ($router) {
require base_path('routes/web.php');
});
}

Sub-domain routing in Laravel on shared hosting

I'm using Laravel framework version 5.1 for my web application that will be run on a shared hosting. Since I have a very limited access to this host, (e.g. I don't have a SSH access, can't create virtual hosts inside the machine etc.) I had to make some tricks to run it smoothly. Here is what I've done so far:
Moved the files inside of the public/ directory to my root directory.
Changed the file paths of auto load registrar in the public/index.php with the new directory.
Everything works as intended except the sub-domain routing. I defined api.myapp.com as wildcard on routes.php but when I try to visit this subdomain, Chrome gives me DNS_PROBE_FINISHED_NXDOMAIN error. Here is the code from routes.php:
Route::group([
'domain' => 'api.myapp.com',
'prefix' => 'v1',
'middleware' => 'cors'
], function () {
// some RESTful resource controllers
});
How can I manage to work this subdomain? What am I missing?
Thanks in advance!

Laravel 5 ElFinder Class replace-this-with-your-middleware does not exist error while browse server

I have configured elfinder in Laravel 5 and also using CKEditor. Everything was fine till until I click on browse server button and then I got "Class replace-this-with-your-middleware does not exist" error.
I have searched the web but I did not find any suitable answer. What can I try next?
You should write your middleware name in elfinder configs.
for example:
'route' => [
'prefix' => 'elfinder',
'middleware' => 'auth'/*replace-this-with-your-middleware*/, //Set to null to disable middleware filter
],
image

Resources