Support the ongoing development of Laravel.io →
IOC Views Blade
Last updated 2 years ago.
0

Facades are supposed to live in global namespace. Try to use \Ajax::test() instead of Ajax::test in your controller, and see if it works. If it doesn't, your alias is not registering properly.

0

In my controller it work perfectly in both ways \Ajax::test() and simply Ajax::test() but is not working if I call it from my template file in this way {{ Ajax::test() }} or {!! Ajax::test() !!}

I'm also deleted the cache with php artisan cache command and also force to regenerate the compiled.php file that is inside the /vendor folder..but still nothing.

The alias is registered into the app.php file like any other Facade aliases.

any other ideas?

Last updated 9 years ago.
0

Right, you should also remove use App\Facades\Ajax\Facade\Ajax; from your controller.

Or, alternatively, try Ajax::test() in php artisan tinker console.

0

Ok..done already this test using tinker with two different facade defined in the same way..below the result:

Psy Shell v0.4.4 (PHP 5.5.9-1ubuntu4.9 — cli) by Justin Hileman
>>> Currency::test()
hello Currency⏎
=> null
>>> Ajax::test()
PHP Fatal error:  Class 'Ajax' not found in eval()'d code on line 1

both are in app.php aliases and also registered into the FacadeServiceProvider that is loaded into the app.php as showed above.

full FacadeServiceProvider code

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Facades\Currency\Currency;
use App\Repositories\Currency\CurrencyEloquent;
use App\Currency as CurrencyModel;
use App\Facades\Language\Language;
use App\Language as LanguageModel;
use App\Repositories\Language\LanguageEloquent;
use App\Facades\Helper\Helper;
use App\Facades\Ajax\Ajax;

class FacadeServiceProvider extends ServiceProvider {

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot() {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register() {

        // Repository Facade
        $this->app->bind('currency', function($app) {
            return new Currency(new CurrencyEloquent(new CurrencyModel()), new LanguageEloquent(new LanguageModel()));
        });

        // Language Facade
        $this->app->bind('language', function($app) {
            return new Language();
        });

        // Helper Facade
        $this->app->bind('helper', function($app) {
            return new Helper(
                    $this->app->make('App\Repositories\Generic\GenericInterface'), 
                    $this->app->make('App\Repositories\Auction\AuctionInterface'), 
                    $this->app->make('App\Repositories\Lot\LotInterface'), 
                    $this->app->make('App\Repositories\Good\GoodInterface')
            );
        });

        // Ajax Facade
        $this->app->bind('ajax', function($app) {
            return new Ajax();
        });
        
    }

}

ideas?

Last updated 9 years ago.
0

Does the log file have a backtrace for the "Class not found" error?

0

The test :

class AjaxTest extends TestCase{
    //put your code here
    
    public function tearDown() {
        parent::tearDown();
        Mockery::close();
    }
    
    public function testTest(){
        \Ajax::shouldReceive('test')->withAnyArgs();
//      \Currency:shouldReceive('test')->withAnyArgs();       // WORK FINE
        
    }
    
}

The trace :

PHPUnit 4.6.6 by Sebastian Bergmann and contributors.

Configuration read from /var/www/html/immogobid/phpunit.xml

.PHP Fatal error:  Class 'Ajax' not found in /var/www/html/immogobid/tests/AjaxTest.php on line 24
PHP Fatal error:  Uncaught exception 'Illuminate\Container\BindingResolutionException' with message 'Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.' in /var/www/html/immogobid/vendor/laravel/framework/src/Illuminate/Container/Container.php:785
Stack trace:
#0 /var/www/html/immogobid/vendor/laravel/framework/src/Illuminate/Container/Container.php(656): Illuminate\Container\Container->build('Illuminate\Cont...', Array)
#1 /var/www/html/immogobid/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(644): Illuminate\Container\Container->make('Illuminate\Cont...', Array)
#2 /var/www/html/immogobid/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(152): Illuminate\Foundation\Application->make('Illuminate\Cont...')
#3 /var/www/html/immogobid/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(73): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /var/www/html/immogobid/vendor/laravel/framework/src/Illuminat in /var/www/html/immogobid/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 785

really don't know what to do..I check everything. I understand that for some reason this class is not instantiated by laravel but don't know why...Also look like any other facade I define are not working anymore..I'm gonna try to put the same code in a fresh project and see what happen! I'll let you know.

Last updated 9 years ago.
0

Ok..same code on different project and it work perfectly! what can I do? I can't rewrite all the code because is a big project...any ideas? thank you all..

0
Solution

Ok..reload all my code from my machine to the server, reset all permission and the problem is fixed! Thank you Xum! Probably there was something missed or some file permissions.

Problem fixed.

0

Bloody file permissions!

I'm moving from Windows to Mac at the moment and this is a constant issue.

I'm actually looking at going on some kind of network admin course so I can get my head round this once and for all

0

Sign in to participate in this thread!

Eventy

Your banner here too?

luca83 luca83 Joined 27 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.