jeudi 4 février 2016

Laravel 5 - insert mutiple users

I have a simple User - Department relationship. My User Model has the following

public function department() {
    return $this->belongsTo('App\Department', 'departmentId');
}

And my Department Model has

public function user() {
    return $this->hasMany('App\User');
}

At the moment I am working with the departments side of things. My index function looks like the following

public function index() {
    $departments = Helper::returnDepartmentsFromLdap();

    return view('departments.index', compact('departments'));
}

What it basically does it gets all the departments from LDap (Active Directory) and displays them. On the index page for departments, I have

{!! link_to_route('departments.updateDepartments', 'Update Database', null, array('class' => 'btn btn-info')) !!}

So the database can be updated if new departments are added to our server. I do not have a create function as it is not needed.

Anyways, at the moment, my routes are like so

Route::model('departments', 'Department');
Route::bind('departments', function($value, $route) {
    return App\Department::whereId($value)->first();
});
Route::resource('departments', 'DepartmentsController', ['except' => ['show', 'edit', 'create', 'delete', 'update', 'destroy']]);
Route::post('departments/updateDepartments', array('as' => 'departments.updateDepartments', 'uses' => 'DepartmentsController@updateDepartments'));

And in my updateDepartments function I am simply doing the following for now

public function updateDepartments()
{
   dd("TEST");
}

If I click on the button on my index page to update the database, which should trigger the above, I am seeing a MethodNotAllowedHttpException.

Am I missing something obvious here?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire