Closed-based routes vs Controller
Closure function – allows to skip the controllers and perform business logic and generate views. Helps to prototype applications quickly or ideal for testing purpose.
As the application grows closed-based routes will become very complex and confusing.
Route::get('cats/{cat}/edit', function(Furbook\Cat $cat) {
    return view('cats.edit')->with('cat', $cat);
});
Controller – loads a dedicated class and easy to maintain.
Routes using controller
Route::resource('users', 'UsersController', [
    'names' => [
        'create' => 'create_user',
        'index'  => 'users_preview',
        'store' => 'save_users',
        'destroy' => 'user_delete',
        'edit' => 'edit_user',
    ]
]);
Controller
public function index()
{

  $users_array = $this->company->companyUsers(Auth::user()->company->first()->id);
   return view("Users::index", compact('users_array'));
}
It better to use the MVC principle and separate the business logic and let route just do the routing job only.

Leave a Reply

Your email address will not be published. Required fields are marked *