Soorajlal K G
Soorajlal K G

Reputation: 786

Laravel - controllers without routing

I am newbie to laravel. I created new controller - book. This is my code -

class BookController extends BaseController {


    public function index()
    {
        return View::make('book.index');
    }

    public function insert()
    {

        return View::make('book.insert');
    }

}

My routes.php -

Route::get('book/', 'BookController@index');
//Route::any('book/insert', array('uses' => 'BookController@insert'));

When i uncomment 2nd line, i can access insert page. Is it possible to access pages without add them to routes.

Now it produce this error enter image description here

Upvotes: 1

Views: 5505

Answers (2)

krisanalfa
krisanalfa

Reputation: 6438

You may read about resource controller.

Execute this on terminal:

php artisan make:controller BookController

This command will generate BookController.php in your app/controllers folder. Read the code for more information.

Define in your routes/web.php file:

Route::resource('book', 'BookController');

Actions Handled By Resource Controller:

Route table

Upvotes: 4

Shaunak Shukla
Shaunak Shukla

Reputation: 2347

Route filters provide a convenient way of limiting access to a given route, which is useful for creating areas of your site which require authentication. So it is better to use route.php as Laravel framework indicates. you can add filters to there as well, refer documentation

Upvotes: 0

Related Questions