Laravel home page is not displaying correctly - php

I have my laravel project installed using homestead and I connect to it via SSH using Vagrant(on Windows). The first time I launched my project there was a message indicating i have an error in my public/index.php file indicating that directory specified in 'require' on 14 line is not found it was written like this
require __DIR__.'/../vendor/autoload.php';
then I just replaced this line of code with directory of welcome.blade.php file (require .../welcome.blade.php) (the home page of Laravel) and this page displayed each time I went to my project website but there was another message displayed saying
Illuminate\Foundation\Application' not found in
/home/vagrant/code/myProject/bootstrap/app.php on line 14.
I think that is because of the laravel version installed enter image description here
What I find quite suspicious is that I haven't got env file and vendor folder inside my project folder. vendor folder was located in AppData/Roaming/Composer folder by default. I just moved that folder to my project folder

First thing, Revert the changes within public/index.php back to how it was. That deals with autoloading and bootstrapping the laravel application and should never really be changed.
Now ssh to your vagrant box and within the laravel project, run cp .env.example .env and then edit the newly copied .env file to have all your details for DATABASE and APP_NAME.
Next, go into your project, and run composer install and this will install all the needed dependencies from the composer.json file.
And lastly, from within your project, you should now run php artisan key:generate to generate the APP_KEY.
This should fix your issue.
I would also advice that you look carefully over the documentation at https://laravel.com/docs

Related

Call to undefined method Illuminate\Database\Query\Builder::fireCustomModelEvent()

I have a project that was created by someone else using Laravel 5.2. I thought I should update this project to at least Laravel 5.3 using the Laravel Guide. When I serve my application it runs correctly but when I try to authenticate myself it gives the error: Call to undefined method Illuminate\Database\Query\Builder::fireCustomModelEvent()
When I discard the changes in the composer.lock file the run composer install, it's fine (obviously does not recognise the Laravel 5.3 changes). This happens when I run composer install.
Try searching your entire project directory for references to fireCustomModelEvent. My suspicion is that you have a library listed in your composer.json file that should have been updated and didn't get updated as part of your migration.
If you have any listings in your vendor folder that turn up results, you will need to update the corresponding package in your composer.json file.

Issue with key (cipher error) when changing laravel folder structure

I am changing laravel 5.3 folder structure. What I exactly do is basically move all the content from public folder to root folder, and then all the other files besides public folder to the new created folder - project. Then I update the require paths in index.php, and when I try to run the project via XAMPP, I'm getting this error.
I am pretty sure that the key is set correctly, because I haven't changed anything else but the folder structure and paths, and the project worked before this folder structure change. It seems to me that program can't locate the .env file.
Try running
php artisan config:clear
and
php artisan key:generate
I followed this post

Laravel, dump-autoload without Shell Access

I have two controllers with the same name:
app\controllers\CareersController.php (for public use)
app\controllers\Admin\CareersController.php (for admins)
Because of the naming conflict, I added namespace admin; to the admin controller.
Everything works fine locally but when I uploaded the new admin controller to my server, I get an error: Class Admin\CareersController does not exist
From what I understand, the fix is:
php artisan dump-autoload
and composer dump-autoload
However, I don't have Shell access to run those commands and composer isn't installed on the server anyway. So, is there a way to reload the auto-load file without Shell access?
Run composer dump-autoload locally. Then, in your hosting site,
you can update two files, autoload_classmap.php and autoload_static.php, manually in vendor/composer folder. I prefer to copy and paste the added classes from local to the hosting server.
You dont need shell access. Artisan includes a dump-autoload function. You can just it via a PHP call within your app:
Route::get('/updateapp', function()
{
\Artisan::call('dump-autoload');
echo 'dump-autoload complete';
});
Edit: just noticed you wrote "composer isn't installed on the server anyway". Not sure what will happen - try the command above and let us know.
If it doesnt work - then just run composer dump-autoload locally - then upload your new autoload.php.
As a side point - is there any option to switch servers? You going to keep running into various issues if you dont have command line & composer access. You could just use Forge and spin up a new server on DigitalOcean, Linode etc in less time than it would take to fix this issue :)
I was using a shared hosting by client's requirements and did not have access to ssh or composer, what I did was to composer dump-autoload on my local machine and then I figured that for my project autoloader just updates composer directory in my vendor directory, so I just re-uploaded that one folder after each dump-autoload and not all vendor directory
Edit:
Another pitfall for me that generated the same error but the cause was something else, I develop on Windows machine in which file and directory names are case insensitive when deploying to Linux server, the framework could actually not find my controllers so I changed
Route::get('/news', 'newsController#index');
to
Route::get('/news', 'NewsController#index');
now it is working, autoload is doing it's job correctly

Laravel 4 - class not found on live server

I'm uploading my laravel 4 app to a testing server which is shared hosting.
I'm uploading to a password protected directory which has a .htaccess file within it. My subdomain points to the public folder.
For the most part they app is working as expected I can log in, view most of the pages however every class that I have created such as a helper class and additional controllers are not being found on the live server yet all works on my local environment.
I've redone a composer dump-autoload and uploaded the composer.json file
I'm not sure where to start with this.
In my upload I've included all the files and folders to the live server (twice now). I read somewhere else I should namespace my classes but why would this help if the main laravel controllers do not namespace?
Confused - all help appreciated
When you do a composer update, if Composer finds anything new it will update some files in the folder
vendor/composer
Like the file autoload_classmap.php.
So, you have to reupload at least this folder too.
Maybe it's about git, you are pushing changings with some certain case sensitive Folders and Files, but git is changing this therefore it will work on Mac and Windows OSs but not on the server.
just use this command:
git config core.ignorecase false
above command for the current repository and you may add --global just after config keyword.
please note that ignorecase option available since version 1.5.6 and I assume you are running 2.0.x but just mentioning!

Setting up preview of Yii2

The Yii2 preview was recently released and is available on github. I want to take it for a test drive, but the "documentation" so far gets outdated almost instantly since it is still under heavy development. I have tried to follow this guide on creating a simple CRUD app with Yii2, but it fails at the step:
php yiic.php app/create /var/www/yii2
With the error:
Could not open input file: yiic.php
Indicating that there is no file called yiic.php. The only folder within the framework folder is yii (framework/yii), and within that folder there is no file yiic.php, only Yii.php which when called in the command line gives the command list:
The following commands are available:
- asset
- cache
- help
- message
- migrate
Anyone managed to successfully setup a Yii2 app? Care to share how you got it done?
Seems like yiic has been removed for now, there are alternatives though, so read on.
It's all in the early stages, so the following method could break in the coming days/weeks/months. Therefore use with caution.
There are 2 ways to do this now:
Use composer. (I recommend this option.)
Directly copy the contents of yii2/apps/ directory to your apps directory, depending on the type of app you want to try.
There are currently 2 options for type of app - advanced, and basic. Both are in their respective directories within the yii2/apps/ directory, i.e yii2/apps/advanced and yii2/apps/basic.
For basic go through the basic readme.md, and for advanced go through the advanced readme.md.
The directions for using composer are given in the respective readme.md files. Including them here for completeness:
Basic app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial
Access app from http://localhost/my_yii2_trial/www
Advanced app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-advanced my_yii2_trial
According to readme, after step 2 app should be accessible, but composer was failing(see issue 439). With schmunk's tip, ran the install or install.bat command that gets copied by composer: ./install . Selected development environment (by entering choice 0 in the instructions that show up when running install command). Update: The command has been renamed to init, composer doesn't fail anymore, with fix from Qiang (check the issue 439 for more details).
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Here's how to copy the directory and get it working:
Basic app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/basic/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/www/index.php file to point to the correct path for Yii.php.
For me it was within yii2/framework/yii/
comment the line that tries to include ../vendor/autoload.php file, I couldn't find that file anywhere, so its probably for some future use. it is the autoloader provided by composer.
Access from browser : http://localhost/my_yii2_trial/www
Advanced app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/advanced/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/frontend/www/index.php file to point to the correct path for Yii.php. Similarly modify backstage/www/index.php.
comment the line that tries to include ../vendor/autoload.php file in both the index.php of backstage and frontend.
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Some important links to read more about this: issue 77, issue 108, issue 131, and wiki comment.
I am not sure how composer's autoloader is being used, so can't comment on that. Also in future versions, backstage might be renamed to backend.

Categories