meowfishcat
meowfishcat

Reputation: 127

Laravel Subdirectory Views

what I'm trying to do is set it up so that the user can go to "/project/index" ("/" being the route ofc) but I'm not quite sure how to do it in laravel?

What I currently have:

Routing:

Route::get('project.index', array('as' => 'project/index', 'uses' => 'ProjectController@indexPage'));

Also in routing:

View::addLocation('project'); //Project View View::addNamespace('project', 'project');

In my Project Controller:

public function indexPage()
    {
        return View::make('index', array('pageTitle' => 'Project Index'));
    }

Any ideas? Thanks in advance.

PS: It's Laravel 4

Upvotes: 1

Views: 1392

Answers (1)

Wader
Wader

Reputation: 9883

You have your routing a little wrong. Try out the following

Route::get('project/index', ['as' => 'project.index', 'uses' => 'ProjectController@index']);

So the first parameter into the Route::get() function should be the URL the user is visiting for example http://example.com/project/index. The as key in the array provided is the name you're giving to the route.

By giving the route a name you can use this throughout your application, rather than using the url the user is visiting. For example you might want to generate a link to your route

<a href="{{ route('project.index') ">Link</a>

This will generate a link to http://example.com/project/index. This makes it convenient in the future should you wish to change your URLs without changing lots of links throughout your view files.

Route::get('foobar/index', ['as' => 'project.index', 'uses' => 'ProjectController@index']);

The URL generated through route('project/index') would now be http://example.com/foobar/index

Checkout the routing documentation for further information http://laravel.com/docs/4.2/routing

Upvotes: 1

Related Questions