TheNiceGuy
TheNiceGuy

Reputation: 3730

How can I access global classes from within a package?

I created a package which also contains his own controller files and also a router.php file.

My problem is that i can't access anyone of the main classes like Schema or View.

I always get a Error: Class not Found error.

Upvotes: 1

Views: 111

Answers (1)

Jamie Schembri
Jamie Schembri

Reputation: 6075

I'm assuming you're using namespaces in your package, which you should be. As a result, you need to precede global classes with a backslash to access them. For example, View::make() becomes \View::make().

Alternatively, you could import the Facades:

<?php
namespace Your\Namespace;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;

//...

View::make($view, $data);

See the PHP namespace FAQ.

Upvotes: 1

Related Questions