2015-07-19 138 views
0

目前我正在使用laravel。當我想通過視圖訪問控制器時。我收到我的方法未找到的錯誤。未找到Laravel控制器功能

Action App \ Http \ Controllers \ RidesController @ edit未定義。 (查看: C:\ WAMP \ WWW \資源\意見\遊戲機\ rides.blade.php)

但是當我嘗試它的工作原理自嘆不如指數的方法?我該怎麼辦?

這是我rides.blade.php:

</thead> 
          <tbody> 
           <tbody> 
            @foreach($rides as $ride) 
            <tr> 
             <td><a href="{!! action('[email protected]',$ride->id) !!}">{!! $ride->id !!}</a> </td> 
             <td>{!! $ride->created_at !!}</td> 
             <td>{!! $ride->beginstand !!}</td> 
             <td>{!! $ride->eindstand !!}</td> 
             <td>{!! $ride->van !!}</td> 
             <td>{!! $ride->naar !!}</td> 
             <td>{!! $ride->bezoekadres !!}</td> 
             <td>{!! $ride->geredenroute !!}</td> 
             <td>{!! $ride->karakterrit !!}</td> 
             <td>{!! $ride->toelichting !!}</td> 
             <td>{!! $ride->kilometerszakelijk !!}</td> 
             <td>{!! $ride->kilometersprive !!}</td> 
            </tr> 
            @endforeach 
           </tbody>  

我的路線控制器:

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use App\Http\Requests; 
use App\Http\Controllers\Controller; 
use App\models\ridesregistration; 
use App\Http\Requests\RideFormRequest; 

class RidesController extends Controller 
{ 
    public function index() 
    { 
     $rides = ridesregistration::all(); 
     return view("rides.rides",compact('rides')); 
    } 

    public function create() 
    { 
     return view('rides.create'); 
    } 

    public function store(rideFormRequest $request) 
    { 
     $rides = new ridesregistration(array(
      'beginstand' =>$request->get('beginstand'), 
      'eindstand' =>$request->get('eindstand'), 
      'van' =>$request->get('van'), 
      'naar' =>$request->get('naar'), 
      'bezoekadres' =>$request->get('bezoekadres'), 
      'geredenroute' =>$request->get('geredenroute'), 
      'karakterrit' =>$request->get('karakterrit'), 
      'toelichting' =>$request->get('toelichting'), 
      'kilometerszakelijk' =>$request->get('kilometerszakelijk'), 
      'kilometersprive' =>$request->get('kilometersprive') 
      )); 
     $rides->save(); 
     return redirect('/maakrit')->with('message','Rit '.$rides->id.' is succesvol aangemaakt.'); 
    } 

    public function edit($id) 
    { 
     $rides = ridesregistration::whereId($id)->firstOrFail(); 
     return view('rides.edit',compact('rides','rides')); 
    } 
} 
+0

你爲什麼要使用小寫名稱爲模型的目錄和類名?該公約顯然是CamelCase。 –

回答

0

根據laravel 5文件建立 http://laravel.com/docs/5.0/controllers

ü應使用with動作命名空間( )幫手

http://joxi.ru/8AnBMZXSv8lpAO

如果我們將深入挖掘\照亮\路由\ UrlGenerator ::行動

we`ll看到:

public function action($action, $parameters = [], $absolute = true) 
{ 
    if ($this->rootNamespace && !(strpos($action, '\\') === 0)) { 
     $action = $this->rootNamespace.'\\'.$action; 
    } else { 
     $action = trim($action, '\\'); 
    } 

    if (!is_null($route = $this->routes->getByAction($action))) { 
     return $this->toRoute($route, $parameters, $absolute); 
    } 

    throw new InvalidArgumentException("Action {$action} not defined."); 
} 

,你的行動( 'RidesController @指數')的作品,因爲它是在路線中定義。 和你的動作('RidesController @ edit',$ ride-> id)不起作用,因爲它不在路線中。

在您的應用程序/ HTTP/routes.php文件定義了這個控制器動作

+0

感謝您的回覆。但是,我可以如何訪問RidesController @ index而不是RidesController @ edit呢? – Jamie

+0

顯示您的應用程序/ Http/routes.php – M0rtiis

+0

Thankyou運作良好! – Jamie