mardi 28 juin 2016

Object not being passed to controller

I am struggling with something I am pretty sure I am doing incorrectly. I have a Departments model which has the following route

Route::resource('departments', 'DepartmentsController', ['except' => ['show', 'edit', 'create', 'delete', 'update', 'destroy']]);

It uses active directory to update the database, no user input is involved. I have now come to the point where a department can have many objectives. So I have created a DepartmentObjectives model and set the relationships. I then done the following in my routes file

Route::model('departmentObjectives', 'DepartmentObjectives');
Route::bind('departmentObjectives', function($value, $route) {
    return App\DepartmentObjectives::whereId($value)->first();
});
Route::resource('departmentObjectives', 'DepartmentObjectivesController', ['except' => ['show', 'store', 'delete', 'destroy']]);

Now on the index file for departments, I have the following

@foreach($departments as $department)
    <tr>
        <td>  </td>
        <td>  </td>
        <td>{!! link_to_route('departmentObjectives.create', 'Get Objectives', array($department->id), array('class' => 'btn btn-info')) !!}</td>
    </tr>
@endforeach

But within the DepartmentObjectives Controller, if I do the following it outputs an empty Department object

public function create(Department $department)
{
    dd($department);
    return view('departments.objectives', compact('department'));
}

What is the best way to link the department objective to the department?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/29k5vUC
via IFTTT

Aucun commentaire:

Enregistrer un commentaire