Home > Net >  I can't see any view in my first laravel project
I can't see any view in my first laravel project

Time:08-16

I'm new to Laravel. I'm trying to run my first Laravel project. When I go http://localhost/my_project then it's working but when I go http://localhost/my_project/public/index.php, the page is not working.

Also, I tried to copy the index.php on my project root file to the public folder but don't work. Now how can I solve the problem?

The index.php:

use Illuminate\Contracts\Http\Kernel;

use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {

    require $maintenance;
}

require __DIR__.'/../vendor/autoload.php';


$app = require_once __DIR__.'/../bootstrap/app.php';


$kernel = $app->make(Kernel::class);


$response = $kernel->handle(

    $request = Request::capture()

)->send();

$kernel->terminate($request, $response);

CodePudding user response:

First of all, You need to do some work in terminal to create and start the laravel server. So open your terminal and do the below procedures,

Command for creating a laravel project,

composer create-project laravel/laravel --prefer-dist projectname

Then get into the project and start the laravel project to see a view

cd projectname
php artisan serve

The default url and port that laravel works on is http://127.0.0.1:8000 which you can see in the terminal itself. Type the url and port in the browser where you can see the initial laravel page.

To change or create a view, You need to check routes/web.php and resources/views/welcome.blade.php. Just change the contents in the welcome.blade.php and refresh the browser. You can see changes in the browser.

Also refer the below link for more clarification,

https://laravel.com/docs/9.x/views

CodePudding user response:

If you want to start first fresh project laravel. Please run php artisan serve. If you want to see page you want, you must define route first. The route file located in folder routes then open file web.php. There you can create a router that goes to the page you want. Example:

Route::get('/my_view', function(){
  return view('test');
});

Then make your view file in Resources->views->test.blade.php.

CodePudding user response:

If you start with a new Laravel project.

First, you have to serve using, php artisan serve.

Then add http://127.0.0.1:8000 on your browser

I hope this helps.

In addition, the views are located on app\resources\views\welcome.blade.php

The views folder contains the content of the user interfaces of your website, in layman's terms.

You can add blades. I recommend you to learn about routes and blades.

CodePudding user response:

If you're new, I'd recommend watching a Laravel MVC Tutorial first. This will get you started with how to make a project and continue growing on it. Also, this would probably solve all of your questions for now

  • Related