digjack
digjack

Reputation: 295

laravel route work wrong to direct to views

I am a new laraveler, now I work with a problem about laravel. I want the / direct to a anguler index.html. and others route to laravel controller. but when the \ direct well . the others routes work wrong to a views directory.
the \app\Http\route.php like follows :

Route::get('/',function(){
    return File::get(public_path().('/views/index.html'));
});

Route::get('scan', "userController@Scan");
Route::get('check', "userController@Check");
Route::get('login', "userController@Login");

the directy is something like follows:

├── app │ ├── Http │ │ ├── route.php //route file │ ├── Library │ ├── Providers │ ├── Services │ ├── User.php │ └── views
│ │ ├── Index.php // php index file , the entry for nginx server │ └── .......... ├── bootstrap │ ├── app.php │ ├── autoload.php │ └── cache ├── config │ ├── app.php │ └── view.php │ └── .......... ├── public │ ├── bower_components │ ├── css │ ├── data │ ├── index.bak │ ├── index.html //angular index file │ └── scripts │ └── ..........

now when I access to http://hostname/scan it comes 404 no found.

and the log like follows: ``` *2221 open() "/service/angular-laravel/app/views/scan" failed (2: No such file or directory), client: x.x.x.x, server: hostname, request: "GET /scan HTTP/1.1", host: "banliyun.com:8081"

```

as I was a little confuse with how the route work. can someone tell me why it will route to /views directory where place the laravel index page.

Upvotes: 0

Views: 184

Answers (2)

Shìpu Ahamed
Shìpu Ahamed

Reputation: 480

In AppServiceProvider class boot method add below line:

View::addLocation(public_path('views')); 

Rename index.html file as index.blade.php and then follow below line in your route.php

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

Upvotes: 0

Mauran Muthiah
Mauran Muthiah

Reputation: 1229

Save your index.html as index.blade.php in /resources/views/index.blade.php and you change your route to the following code:

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

Upvotes: 1

Related Questions