Laravel: Class not found Exception - php

In my Laravel project, if have a file app/lib/Formatter.php, with an class Formatter.
From a Controller i am importing this php file using use App\Lib\Formatter;
In my local development enviroment, I can access methods from the Formatter in my Controller. But when i deploy the laravel project to a share hosting, i can't access Formatter. Laravel returns this error message:
"Class 'App\Lib\Formatter' not found"
After it works localy, i don't have any idea, why it shouldn't work on shared hosting.

Linux is casesensitive. You should rename your folder from lib to Lib.
If your folder tree looks like App\lib\Formatter.php rename your library to App\Lib\Formatter.php.

Related

Access Core PHP folder inside a Laravel 8 project

Laravel Project is installed in my root directory and I have another project inside root directory with Core PHP ,
COREPHP-PROJECT is the one I want to access , but every time I try to access example.com/COREPHP-PROJECT it's giving me 404 error.
I have tried more than 50 solutions from internet and nothing is working so far.
What I'm doing wrong here?
NOTE: .htaccess file is renamed as I wanted to test without it too.
I think it is actually fine to have a project directory inside the applications root directory. A good application should not be build inside the framework. It should be build with the framework. If in 5 years somehow laravel is not anymore supported you can decouple it more easy and use it in a new framework.
You just need to assign the path to your composer.json under the psr-4 part.
"autoload": {
"psr-4": {
"MainApplication\\": "app/",
"CorePhpProject\\": "CORE-PHP-PROJECT/app/",
But you should only route over the Laravel router.
You can add your routes inside laravels RouteServiceProvider.php
Have a look at the documentation:
https://laravel.com/docs/8.x/routing#the-default-route-files
Should look something like this then:
Route::prefix('coreproject')
->group(base_path('CORE-PHP-PROJECT/routes/web.php'));
Then you can call your laravel routes like this
/home
and the project one are called like /coreproject/home
I got into same task of integrating core php folder inside laravel , therefore solution i found that create a core php file with extension test.php in public folder at laravel root, and try to access in browser after php artisan serve, you will find you can access it.

Laravel 5.2 and jenssegers/mongodb REST API with virtualhost

I am creating a REST API with Laravel 5.2 and I'm also using MongoDB with the jenssegers/mongodb library. I have a virtualhost for my application so I can go to the url eg: http://myapp.local.com and simulate how it would be on the real server and as I have some other Laravel projects on dev right now, it is more organised to have them this way.
The virtualhost is pointing to the public folder of my application and it's working correctly.
This project is just starting so everything is being built right now. In order to check the database I created a very simple PostsController just to see if the connection and the results were returned correctly. I added Route::resource('/posts', 'PostsController'); in my routes.php so I could start doing some tests of basic CRUD operations.
When I use php artisan serve and access this route with http://localhost:8000/posts the results are brought correctly but when I try to access via http://myapp.local.com/posts I get this error:
FatalErrorException in Client.php line 56:
Class 'MongoDB\Driver\Manager' not found
Any ideas why this is happening?

Phalcon php - Undefined namespace Phalcon

I am working on a project in php Phalcon.
I am working with the Xampp server. The installation process that I followed is on this link:
http://docs.phalconphp.com/en/latest/reference/install.html
I am following the documentation on the website as guide and tutorial.
My problem is, every time I type "class MyClass extends \Phalcon\Mvc\Model"
it says undefined namespace "Mvc" and in other files it also gives error that Phalcon is an undefined namespace.
The installation seems okay.
Please help me out.
I think this is not really a problem with the installation of Phalcon.
I have recognized the same behaviour of my IDE because Phalcon is only loaded as an extension of PHP and not available as real PHP files which can be indexed by your IDE.
The easiest way to check if install was ok is to create a info.php in your project root.
<?php
phpinfo();
If you open this file in browser it should show a block with information about phalcon.
There is a script that creates stub files for you that can be integrated in you project.
https://github.com/phalcon/phalcon-devtools/blob/master/ide/gen-stubs.php
If these files are indexed by your IDE, the message of Undefined namespace should be gone.
If your code works. And IDE shows Mvc undefined namespace then you have to install Phalcon developer tool plugin for your IDE. the plugin is available for PHPStorm. Phalcon is a C extention and for this if you not install developer tool plugin then IDE will show undefined namespace.
Phalcon has different ways to use model like register model class, register namespace or register dir. If you create the model by command rather than manually write code you will get the proper base model class to extend. If still problem then there is problem with Phalcon installation.
Use --namespace="" for model:
phalcon create-model profiles --namespace="Application\Models"
For scaffold:
phalcon create-scaffold profiles --ns-models="Application\Models" --ns-controllers="Application\Controllers"
If you do not register the model namespace and register only model directory then edit the model file after creation and remove the namespace definition.
first check if php load phalcon module. for that in terminal type
php -r "echo phpinfo();" | grep 'phalcon'
if everything went write you should see line
phalcon => enabled
in windows grep wont work and you should look for that line yourself.

Laravel: How to include file from Vendor folder in Laravel

I am trying to include the YouTube Analytics Service of Google but I can not access it through the Vendor folder.
include(app_path.'path/to/analytics/Google_YoutubeAnalyticsService.php')
It is not working, because it defaults to the App folder.
How can I get out of the App folder and into the Vendor folder (where the YouTube Analytics file is at)?
The error is {
include(C:\xampp\htdocs\mysite\app/path/to/analytics/Google_YoutubeAnalyticsService.php):
failed to open stream: No such file or directory
From where do you want to include that file ?
Place a reference to your file in composer.json autoload object:
"autoload": {
"files":["your_file_path"]
}
Run composer dumpautoload, and you'll have your file :)
Actually you have in the helpers function the path so basically the function base_path give the direction to the root of your project so
echo base_path() . '/vendor';
Should be the route to your vendor folder.
You can se all the documentation in
Helper Functions Laravel
Be sure that you are seeing the documentation of the laravel version that you are using (I put the link for the 4.2 version).
This question was asked a long time ago and the answers reflect that. Most the time now all you need to do is import it using the "use" statement if you installed it with composer. Composer will already reference all the important directories.
It should be something like this, but it will vary depending on the project.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\Class;
That could include a base class as well as some exception classes.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\ClassException;
Usually most packages if compliant with modern composer and php standards work in this fashion.

Error on Zend controller creation

I'm attempting to build a test project with the Zend framework and using MAMP to run it on my local host.
The project creation works fine; I navigate to my htdocs directory and use zf create project my_zend to create the scaffold.
My error comes when I try to create a controller "students" by using the following command zf create controller students, however, once this command runs it outputs the following error:
Context by name servicesDirectory does not exist in the registry.
Where does this error come from?
I had the same problem, here is how I fixed it, check for the line:
<servicesDirectory enabled="false"/>
In the .zfproject.xml file and remove it.
You might get this error if you have another version of zend some where in the path. If you have one try deleting it and using the latest or the version you wish to. This worked for me in xamp on windows 7 hope it works for you

Categories