1
votes

I was making a basic CRUD app from a tutorial but realised I wanted to mask the feature inside an admin folder.

The feature was a blog management system (index, create, show, delete etc) and this all ran from domain.com/blog.

Since then, I have built a user system and a protected admin area so have decided to move the view files into an admin folder.

To counter this change, I asked on here and was instrcuted to wrap my resource route in this:

Route::group(array('before' => 'is_admin', 'namespace' => 'admin', 'prefix' => 'admin'), function()
  Route::resource('blog', 'BlogController');
});

Then move my BlogController into an admin folder in my controller folder, then add a namespace to that controller:

namespace Admin;

and add a backslash before the BaseController.

This line here:

return View::make('admin/blog.index', compact('blogs'));

Was causing errors, so I had to add a backslash before the View::

return \View::make('admin/blog.index', compact('blogs'));

How do I not have to do that for all the classes?

And then once that is okay, my index file contains:

{{ link_to_route('blog.create', 'Add new blog') }}

Which is returning undefined route errors... where am I going wrong? The resource route should be catching these routes etc surely? Seems alot of work to simply make the BlogController work in an admin directory...

1

1 Answers

0
votes

This is how namespaces work. You can import namespaces adding:

use View;

and now you will be able to use just View and not \View in other places of your file so the beginning of your file should look like this:

<?php namespace Admin;
   use View;

But you will need to add this to each file you moved to namespace Admin;

You could also read How to use objects from other namespaces and how to import namespaces in PHP to understand it a bit better.