Laravel 4: using views in a package

I created a very basic application in Laravel 4, which is what I will use repeatedly in different projects, so it makes sense to convert it to a package until I go too far, but I'm struggling to make changes to make it work, which, in my opinion, is largely explained by how to access various objects that are usually available in the application, for example View :: make

I had the following code working in the application:

class PageController extends BaseController { public function showPage($id) { //do stuff return View::make('page/showPage') ->with('id', $id) ->with('page', $page); } 

for the package, I have the following:

 use Illuminate\Routing\Controllers\Controller; use Illuminate\Support\Facades\View; class PageController extends Controller { public function showPage($id) { //do stuff return View::make('page/showPage') ->with('id', $id) ->with('page', $page); } 

However, this does not load the blade template, which is located at:

 workbench/packagenamespace/package/src/views/page/showPage.blade.php 

and does not work:

 return View::make('packagenamespace/package/src/page/showPage') 

Also, I wonder what I did using the operators in which I use the facade object correctly, it seems to me that there should be an easier way to access things like the View object?

+6
source share
1 answer

You should read the docs: http://four.laravel.com/docs/packages

In particular, the part explaining loading views from packages;)

 return View::make('package::view.name'); 

If you do not want to use:

 use Illuminate\Support\Facades\View; 

Just do:

 use View; 

Or even without using an operator:

 \View::make('package::view.name'); 
+15
source

All Articles