I have never used Laravel before and am trying to get my first controller working, using Laravel 10.45.1.
The documentation says I should put this in my route file. In my case, I put these lines in /routes/web.php
.
use AppHttpControllersTestController;
Route::get ('/test', [TestController::class, 'abc']);
In app/Http/Controllers/TestController.php
, I have the following:
namespace AppHttpControllers;
use IlluminateHttpRequest;
use IlluminateViewView;
class TestController extends Controller
{
public function __construct ()
{
}
public function abc ()
{
return view ('welcome'):
}
}
I also have a /public/test/index.php
file, which contains:
echo ('in index.php');
When I go to the page in my browser, it tells me it is in index.php
. It never invokes my controller function. If I delete the index file from the public subdirectory, it gives me a 404.
What do I need to do to get it to invoke my controller function when it receives a request for that route?
2
Answers
You need to create the "welcome" view.
Create the view in
resources >> views >> welcome.blade.php
Whatever you put in that file, when you visit the /test route, your function "abc" will be executed.
@Zephyrus if u developed on local:
when u run
php artisan serve
default url path to ur site isbut u say u are going to
i thin this is problem and when u go to ‘localhost’ the nginx was rsponsed on port ’80’!
for see ur website u should search ‘localhost’ on port ‘8000’. so just go to ‘http://localhost:8000’.
and if you are on server thst i think this is not correct! than u should fix ur config server file on server!