I am migrating a Laravel 4.2 application to Laravel 5.1.
During bootstrap, when loading the mail configuration file (config/mail.php), I want to read my SMTP configuration from DB and cache it.
In order to do that I use an Eloquent model class, in which I use the Cache facade's remember() function to get the data I need.
It used to work in 4.2, but after switching to 5.1, I get the following error message:
Call to a member function remember() on a non-object
This happens after I put the following line at the top of the class:
use Illuminate\Support\Facades\Cache;
Without that line I got a Class 'Cache' not found error message.
Any idea what am I missing? Is this even possible in 5.1?
Thanks a lot!
Related
I am running ide-helper in my Laravel Framework 8.33.1 project. To generate the model facade declarations (command: php artisan ide-helper:models) I am getting this error:
Exception: Class 'Database\Factories\XXXFactory' not found
Could not analyze class App\Models\XXX.
Do I need a factory for each model or why is that?
In your Ide-helper config file, set 'include_factory_builders' to false
config/ide-helper.php
'include_factory_builders' => false,
Seems like this is a known bug with ide-helper 2.9.1, see here:
Github Issue 1188 ide-helper
How I solved it:
I removed
use HasFactory
from all models which do not have an according factory class implemented.
Hi I got this errors in Lumen
FatalErrorException in RedirectResponse.php line 75:
Call to a member function flashInput() on null
in RedirectResponse.php line 75
at Application->handleShutdown() in RegistersExceptionHandlers.php line 55
at Application->Laravel\Lumen\Concerns{closure}()
Here the code which throws the error:
return redirect('formular')
->withErrors($validator)
->withInput();
The error comes from withInput()
The error is happening because Lumen 5.2 does not support sessions. The withErrors() and withInput() methods attempt to set values on the session attribute on the redirector, but the session attribute is null.
From the Lumen 5.2 documentation on validation:
Lumen does not support sessions out of the box, so the $errors view variable that is available in every view in Laravel is not available in Lumen. The $this->validate helper will always return JSON responses with the relevant error messages when validation fails. If you are not building a stateless API that solely sends JSON responses, you should use the full Laravel framework.
Basically, if you're trying to use sessions, you're trying to use Lumen 5.2 in a way it was not intended. You should either be using Lumen 5.1, or using the full Laravel framework. You can read the release notes here on the philosophy change for Lumen 5.2.
I'm having trouble using packages in codeigniter.
My folder layout is:
/applications
/regular_application1
/regular_application2
/common_pkg
In common_pkg, I have models that I want both applications to be able to use. In order to load the package, I added the route to it in $autoload['packages']-
$autoload['packages'] = array(FCPATH.'applications/common_pkg/');
This works fine, in both applications in any controller I can now load the models using:
$this->load->model("Balance_model");
The problem is that after this, I want to load a library from within my regular_applicationx. So I call from within my controller (the controller is in regular_applicationx:
$this->load->library("Selections_library");
But when I try to use the library, I get:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Selections::$Selections_library
I'm surmising from the above that once I set my package to common_pkg in the autoload, CodeIgniter is only looking there for libraries and models. Is there any way to load both from the regular application and common_pkg?
Thanks!
I am currently learning laravel 5 and wanted to implement the repository concept.
as I understand. I should put an ioc.php and the config folder and put my bindings their
Here is my config/ioc.php
<?php
App::bind('QuestionRepository', 'IQuestionRepository');
App::bind('AnswerRepository', 'IAnswerRepository');
I get an error Class 'App' not found in
try prefixing App with \ like \App
For my case in lumen 5.4, undefined 'App' class issue solved by facade definition:
use Illuminate\Support\Facades\App;
In my case, my .env file contained a value with spaces after checking out a new project.
Running php artisan optimize for the first time would throw this error because my Exception handler was trying to use the '\App' global alias for the App facade. Commenting that code showed the real error;
"Dotenv values containing spaces must be surrounded by quotes."
If I use the symfony console command generate:doctrine:crud with --write parameter I get an auto-generated controller working only in the indexAction route, but not in the others (newAction, deleteAction, updateAction). I think the problem is in the form creation.
The resulting error is the following one:
Compile Error: Can't inherit abstract function
Symfony\Component\Validator\ValidatorInterface::validate() (previously
declared abstract in
Symfony\Component\Validator\Validator\ValidatorInterface)
Server Error - FatalErrorException500 Internal in vendor/symfony/symfony/src/Symfony/Component/Validator/Validator/RecursiveValidator.php at line 31
I don't know, how to solve this problem.
This error is the error message you get when running the new validator component in PHP 5.3.8 or older. You need to use at least PHP 5.3.9 to use recent versions of Symfony
The only way to solve this problem is to change ValidatorInterface or to run almost PHP 5.6