1
votes

In Laravel, are all controllers only supposed to have the basic CRUD methods, as shown in the link below?

https://laravel.com/docs/5.3/controllers#resource-controllers

That is, should the only methods in a controller be:

  1. index()
  2. create()
  3. store()
  4. show()
  5. edit()
  6. update()
  7. destroy()

Thanks.

2
Not, it's not. It depends on your (app's) need and you can create any method if you want. The link is about a particular type of Laravel's) controller and you can break the rules if you want. Probably, do some more research.The Alpha

2 Answers

1
votes

No.

A controller can have methods named however you want! If you are creating a RESTful controller, then the names of the methods make sense.

When you create a Resource Controller, then Laravel will save you the pain of writing the routes (you can use Route::resource)

For example: you can do this in YourController.php

function tada() {
return "Tadaaaa";
}

and then in your routes.php, you define a route like

Route::get('tada', 'YourController@tada');

And visiting that route will present you with the string Tadaaaa

Have fun!

0
votes

No, You can have your own functions too. This is just a boilerplate that Laravel provides you to start with.