Laravel call named routes internally php artisan command

Image for post
Image for post

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
Image for post
Image for post
$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
Image for post
Image for post
Image for post
Image for post
Auth::login($user, false); 
auth()->loginUsingId($Admin_id);

Other solutions for protected routes:

Previous Stories You will Love:

Written by

Web geek, Self-taught full-stack web developer, Learning Python, Laravel, Vuejs, UX/UI design, Nuclear Physicist PhD

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store