How to create a new controller in Laravel?

To create a new controller in Laravel, you can follow these steps:

  1. Open a terminal or command prompt and navigate to your Laravel project directory.
  2. Run the following artisan command to create a new controller file:
php artisan make:controller NewController

This will create a new controller file named NewController.php in the app/Http/Controllers directory.

  1. Open the newly created controller file and start adding your desired methods and logic. For example, you can add a new method called index to return a view:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class NewController extends Controller { public function index() { return view('new.index'); } }
  1. Save the controller file.

Note: Make sure you define the proper namespace and extend the base Controller class.

You can now use the newly created controller in your routes or other parts of your Laravel application.