Ad

Laravel 5 Submitted Form To Index Using Resource Route As Well

- 1 answer

Edit:

I am trying to accomplish something simple. On my appointments.index view I have a form. Once the form is submitted, I want to use the values in my query, like so:

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'));
}

One of the methods in my model (they are all similar):

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

What is the best way to do this, if not for the below solution?

OP:

I am getting the following error:

Method App\Http\Controllers\AppointmentsController::store() does not exist

I know it is because of my routes:

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

If I change the post route like so, it works:

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

Question is, why is this (because of the resource route, I understand, but why) and how can I go about "fixing" it so I can still use my routes like the above?

Ad

Answer

The resource route create store action in your controller. You may specify a subset of action to the recourse.

In your case try that

Route::resource('appointments', 'AppointmentsController',
                ['except' => ['store']]);
Ad
source: stackoverflow.com
Ad