简体   繁体   中英

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 在此处输入图片说明

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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM