Organizational Research By

Surprising Reserch Topic

laravel custom classes add alias using -'php,class,laravel,alias'

laravel custom classes add alias  using -'php,class,laravel,alias'

So I want to add a alias for custom classes in order to be able to use them in blade:

namespace App\Classes;

class Requirement
    public static function Test()
        return "hello";

In config/app.php I added a alias like so:

'Requirement' => App\Classes\Requirement::class

Then, I would like to be able to call it in a blade template like

{{ Requirement::Test() }}

But the alias is not working somehow. I also tried composer dump-autoload, but it's still not working.

BTW: Is adding custom classes like that a viable way to implement site-specific logic like retrieving and processing data from a database or is there a better approach?

Edit 1

I created Requirement.php in app/Facades with following content

namespace App\Facades;
use Illuminate\Support\Facades\Facade;

class Requirement extends Facade{
    protected static function getFacadeAccessor() { return 'Requirement'; }

added PageContentProvider.php in app/Providers with the following content


namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class PageContentProvider extends ServiceProvider
     * Register the application services.
     * @return void
    public function register()
        $this->app->bind('Requirement', function($app){
            return new \App\Classes\Requirement();

and in config/app.php the alias


as well as the provider


but it's still not working.

Edit 2

By adding something like



echo "blabla";

inside register(), nothing changes. Does that indicate that PageContentProvider is not even getting loaded?

Edit 3

Since the standard AppServiceProvider gets loaded, I deleted the coresponding entry of AppServiceProvider in config/app.php... and it still worked! Somehow my changes don't get applied. Does anybody have solution for that?

asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.