2016-07-30 70 views
1

我是Laravel 5的初學者。我創建了一個模型(Cars),一個控制器(CarController)和一個視圖(show.blade.php)。但是,每次我嘗試執行我的項目,我得到了同樣的錯誤:Laravel沒有運行我的路線

Sorry, the page you are looking for could not be found. 

1/1 
NotFoundHttpException in RouteCollection.php line 161: 
in RouteCollection.php line 161 
at RouteCollection->match(object(Request)) in Router.php line 821 
at Router->findRoute(object(Request)) in Router.php line 691 
at Router->dispatchToRoute(object(Request)) in Router.php line 675 
at Router->dispatch(object(Request)) in Kernel.php line 246 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
at Pipeline->then(object(Closure)) in Kernel.php line 132 
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99 
at Kernel->handle(object(Request)) in index.php line 54 
at require_once('C:\xampp\htdocs\laravel\public\index.php') in server.php line 21 

這是我的代碼:

Car.php(型號)

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Car extends Model 
{ 
    // 
} 

2016_07_30_135543_create_cars_table.php

<?php 

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateCarsTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('cars', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('make'); 
      $table->string('model'); 
      $table->date('produced_on'); 
      $table->timestamps(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::drop('cars'); 
    } 
} 

CarController.php

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

use App\Car; 

class CarController extends Controller 
{ 
    // 
    /** 
    * Display a listing of the resource. 
    * 
    * @return Response 
    */ 
    public function index() 
    { 
     // 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return Response 
    */ 
    public function create() 
    { 
     // 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @return Response 
    */ 
    public function store() 
    { 
     // 
    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function show($id) 
    { 
     // 
     $car = Car::find($id); 
     return view('cars.show', array('car' => $car)); 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function edit($id) 
    { 
     // 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function update($id) 
    { 
     // 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function destroy($id) 
    { 
     // 
    } 
} 

show.blade.php

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Car {{ $car->id }}</title> 
    </head> 
    <body> 
    <h1>Car {{ $car->id }}</h1> 
    <ul> 
     <li>Make: {{ $car->make }}</li> 
     <li>Model: {{ $car->model }}</li> 
     <li>Produced on: {{ $car->produced_on }}</li> 
    </ul> 
    </body> 
</html> 

routes.php文件

<?php 


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

Route::resource('cars', 'CarController'); 

我嘗試:本地主機:8000/laravel /公/汽車 本地主機:8000/laravel /公/汽車。顯示 localhost:8000/laravel/public/show

我不知道爲什麼會發生這種情況。誰能幫我?

+1

只是'本地主機:8000/cars' :D –

+1

我想你已經發布了整個公關在這裏投下Hhahaha! –

+0

xD Ismail RBOUH,我照你的建議做了。但現在,頁面中沒有任何內容。沒有HTML :( –

回答

0

嘗試其中之一:

http://localhost/laravel/public/cars 

或通過artisan命令爲你的應用程序第一次

php artisan serve 

瀏覽這樣

http://localhost:8000/cars