2016-01-22 52 views
1

编辑:Laravel 5提交了使用资源路径索引的表单

我想完成一些简单的事情。在我的约会。索引视图我有一个表单。一旦提交表单时,我想我的查询中使用的值,就像这样:

AppointmentsController:

public function index(Request $request) 
{ 
    $statusId = $request->status; 
    $labelId = $request->label; 
    $monthId = $request->month; 

    $appointments = Appointment::status($statusId)->label($labelId)->month($monthId)->get(); 

    return view('appointments', compact('appointments')); 
} 

一个在我的模型方法(它们都是相似的):

public function scopeStatus($query, $statusId) 
{ 
    if($statusId) 
    { 
     return $query->where('status_id', '=', $statusId); 
    } 
    else { 
     return false; 
    } 
} 

如果不是以下解决方案,最佳做法是什么?

OP:

我收到以下错误:

方法应用\ HTTP \控制器\ AppointmentsController ::店()不存在

我知道那是因为我的路线:

Route::get('appointments', array('as' => 'appointments', 'uses' => '[email protected]')); 
Route::post('appointments', array('uses' => '[email protected]')); 
Route::resource('appointments', 'AppointmentsController'); 

如果我改变,像这样的布线后,它的工作原理:

Route::post('appointments/anythinghere', array('uses' => '[email protected]')); 

问题是,为什么是这样的(因为资源路线的,我理解,但为什么),以及如何我可以去“修复”,所以我仍然可以使用我的路线像上面?

回答

1

资源路径在您的控制器中创建存储操作。您可以指定追索权的一部分行动。

在你的情况尝试

Route::resource('appointments', 'AppointmentsController', 
       ['except' => ['store']]); 
+0

谢谢,这的确应该工作,但我使用创建一个新的约会的存储方法。我想也许我应该找到另一种方法来完成我想要做的事情。我会更新OP,但:) :) – Hardist

+0

是的,你应该找到另一种方式。你可以在这里看到https://laravel.com/docs/5.1/controllers#restful-resource-controllers资源控制器的工作原理 –