Creating a new controller instance laravel 5.6
In Laravel 5.6, you can create a new controller instance in several ways:
1. Using the make:controller
Artisan command
Run the following command in your terminal:
php artisan make:controller MyController
This will create a new controller file in the app/Http/Controllers
directory with the name MyController.php
.
2. Using the Controller
facade
You can use the Controller
facade to create a new controller instance:
use App\Http\Controllers\Controller;
$controller = new Controller('MyController');
This will create a new instance of the MyController
controller.
3. Using the App\Http\Controllers\Controller
class
You can also create a new controller instance by extending the App\Http\Controllers\Controller
class:
use App\Http\Controllers\Controller;
class MyController extends Controller
{
// Your controller methods here
}
Then, you can create an instance of the controller using the following code:
$controller = new MyController();
Note that in Laravel 5.6, the Controller
class is located in the app/Http/Controllers
namespace, so you need to use the fully qualified namespace when creating a new controller instance.
Once you have created a new controller instance, you can use it to handle requests, respond to HTTP requests, and interact with your application's logic.