Laravel call named routes internally php artisan command

Question:

Solution:

Route::get('/foo/bar','BazController@qux')->name('foo.bar');
Route::post('/foo/bar','BazController@qux')->name('foo.bar');
use Illuminate\Http\Request;$request = Request::create('/foo/bar', 'GET');
$request = Request::create(route('foo.bar'), 'GET');
$request = Request::create('/foo/bar', 'POST', $params);or$request = Request::create(route('foo.bar'), 'POST', $params);
$response = app()->handle($request);
$responseBody = $response->getContent();or$responseBody = json_decode($response->getContent(), true);

php artisan command:

php artisan make:command DispatchFooBar --command=dispatch:foobar
$request = Request::create(route('foo.bar'), 'GET');$response = app()->handle($request);
$responseBody = $response->getContent();or$responseBody = json_decode($response->getContent(), true);
$this->info('foo.bar route has been dispatched successfully');
php artisan dispatch:foobar
Auth::login($user, false); 
auth()->loginUsingId($Admin_id);

Other solutions for protected routes:

Previous Stories You will Love:

Posting daily about Python, Nuclear Physicist PhD