douzhi2017 2015-07-19 12:24
浏览 52
已采纳

未找到Laravel控制器功能

Currently I'm working with laravel. When I want to acces a controller through the view. I receive the error that my method is not found.

Action App\Http\Controllers\RidesController@edit not defined. (View: C:\wamp\wwwesources\viewsidesides.blade.php)

But when I try the index method it works strange enough? What should I do?

This is my rides.blade.php:

  </thead>
                            <tbody>
                                 <tbody>
                                    @foreach($rides as $ride)
                                     <tr>
                                        <td><a href="{!! action('RidesController@edit',$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>    

And my routes controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\modelsidesregistration;
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'));
    }
}
  • 写回答

1条回答 默认 最新

  • dpwgzi7987 2015-07-19 12:32
    关注

    According to laravel 5 documentaion http://laravel.com/docs/5.0/controllers

    u should use namespacing with action() helper

    http://joxi.ru/8AnBMZXSv8lpAO

    if we will dig deeper into \Illuminate\Routing\UrlGenerator::action

    we`ll see:

    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.");
    }
    

    that your action('RidesController@index') works because it is defined in routes. and your action('RidesController@edit',$ride->id) not work becouse it is not in the routes.

    define this controller action in your app/Http/routes.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据