Laravel 5.2 `composer update` broke my app running under Laravel/Homestead - php

I was trying to incorporate redis to my Laravel app after learning about it.
And since it is not enabled by default, i've added a line at composer.json file with this: "predis/predis": "1.1.1" under the require.
Next thing i did was run composer update from my CLI.
Once that was done i got this post update:
Then I visit my app page and got this error.
So I looked on my app\Http\Controllers\Controller.php since it was the line it was referring into and went to check if this files still exists but it was not there anymore.
app\Http\Controllers\Controller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests; <-this
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; <-this
use Illuminate\Foundation\Auth\Access\AuthorizesResources; <-this
class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
}
EDIT: Solved
#ceejayoz thank for poiting that out. the downgrade was what caused it. change the 5.2.0. to 5.2.39 and did composer update that now it's back. I was not aware of my own laravel version since i was just using homestead and it was the default values on the composer.json file. Thanks again!

Related

I have an Error in use Spatie\MediaLibrary\IntercatsWithMedia; and use Spatie\MediaLibrary\HasMedia; in laravel after installing spatie media library

use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\IntercatsWithMedia;
class Post extends Model implements HasMedia
{
use HasFactory, IntercatsWithMedia;
}
Error is following in Problems tab of VSCode
Undefined type Spatie\MediaLibrary\HasMedia;
Undefined type Spatie\MediaLibrary\InteractsWithMedia;
Error removed I used following command in windows cmd in project folder instead of integrated cmd of vscode
composer require filament/spatie-laravel-media-library-plugin:"^2.0"

Unknown function "logout_path" even though symfony security-core is installed

I got the message
Did you forget to run "composer require symfony/security-core"? Unknown function "is_granted" in "...".
when calling template-code
{% if is_granted(constant('Rights::RGT_TOUR_ADD')) %}...{% endif %}
I am using symfony v5.3.7, symfony/security-core and symfony/twig-bridge are both v5.3.7. twig itself is v3.3.2 (just updated the whole stuff). All packages are installed in the "good way" of "symfony composer require..."
There is a bunch of extensions in /vendor/symfony/twig-bridge/Extension and most of them are loaded, but not the SecurityExtension (even though available).
Of course I don't want to hard-code a solution, due to the fact that it would be done in /vendor which is in .gitignore ;)
I already tried forced reinstalling of the package... No change.
Just in case this info is needed... PHP is v7.4.15 x64
Security bundle doesn't have logout_path.
You need controller action with the path having that name:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class SecurityController extends AbstractController
{
/**
* #Route("/logout", name="logout_path")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}
As for is_granted check if symfony/security-bundle is installed, enabled in config/bundles.php, and configured properly in config/packages/security.yaml.

Execute bundle command line

I created a small symfony4 bundle to manage Mysql database backup.
I created a packagist folder to implement it easily.
after install, my package path is:
webDirectory\vendor\fpasquer\symfony-backup-bundle\BackupSymfonyBundle.php
I'm able to use every class from this bundle excepted commands.
This is one command:
<?php
namespace Fpasquer\BackupSymfony\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class BackupExportCommand extends AbstractBackup
{
protected static $defaultName = 'Fpasquer:BackupSymfony:extract';
...
}
When I run it :
php bin/console Fpasquer:BackupSymfony:extract
I get this exception:
There are no commands defined in the "Fpasquer:BackupSymfony" namespace.
I'm sure my bundle is installed correctly because in my app:controller I'm able to use DependencyInjection from this bundle
Do you have any idea what's wrong?

How to build an Aggregation query in symfony with doctrine/mongodb?

I'm starting out with Symfony and doctrine/mongodb. I'm trying to do an aggregation query, but I get
Attempted to call an undefined method named "createAggregationBuilder" of class "Doctrine\ODM\MongoDB\DocumentManager"
with something like this:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class TestController extends Controller
{
/**
* #Route("/test", name="test")
*/
public function testAction(Request $request) {
$builder = $this->get('doctrine_mongodb')
->getManager()
->createAggregationQuery('AppBundle:Test');
var_dump($builder);
}
}
I'm quite frustrated now, since every documentation or stackoverflow questions and answers start with
$dm->createAggregationQuery();
and I can't find out what $dm stands for in this case.
I'd really appreciate some help here.
UPDATE
I was looking around in the doctrine/mongodb-odm source code and I found that my version is missing the createAggregationBuilder function from both the DocumentRepository.php and the DocumentManager.php file (both located in /vendor/doctrine/mongodb-odm/lib/Doctrine/MongoDB folder.
How can this be?
I mean composer says that I have version 1.1.6, which is the latest release and on the git repo I can cleary see these methods (DocumentRepository.php, DocumentManager.php)
Silly me. The problem was that I was using the 1.1.6 version of doctrine/mongodb-odm and the Aggregation Builder will only be available in version 1.2. Until than (for anyone being as blind as me), just use the "dev-master" version.
In your composer.json modify the doctrine/mongodb-odm line to this:
"require": {
"doctrine/mongodb-odm": "dev-master"
}
And then run composer update doctrine/mongodb-odm.

Laravel ReflectionException in Controller

I'm trying to inject the class HotelsTransformer without success with the next code:
UserTransformer
<?php
namespace App\Transformers;
class UserTransformer extends Transformer
{
...
}
HotelsTransformer
<?php
namespace App\Transformers;
class HotelsTransformer extends Transformer
{
...
}
ApiHotelsController
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use \App\Hotel;
use \App\Transformers\HotelsTransformer;
class ApiHotelsController extends ApiController
{
protected $HotelsTransformer;
public function __construct(HotelsTransformer $HotelsTransformer)
{
$this->HotelsTransformer = $HotelsTransformer;
dd($this->HotelsTransformer);
}
When I inject UserTransformer, it's all OK, but when I change UserTransformer with HotelsTransformer it throws me this error.
I don't know why is this happening, because I cloned UserTransformer and change its name but same error persists.
Check your following namespace. May be it does not exist or namespace path is not correct
use \App\Transformers\HotelsTransformer;
Try to run composer dumpauto command.
Try running these commands from your terminal (from the root directory of your project)
// use sudo if it asks for the root permission
composer update
composer dump-autoload
php artisan config:clear
Rerun the app/project and try again.
These 2 commands will refresh composer loaded classes and clear the cache to make the project run freshly, hope it helps.!
Ok, I have solved it, the filename was wrong, changed:
app/Transformers/HotelsTranformer.php
to:
app/Transformers/HotelsTranformer.php
1 hour spent on that like a crazy, good job.

Categories