Update multiple database entries via controller I've inherited a Craft site that is a mix of a custom plugin (the main site) plus a Laravel Dingo plugin (behind which the bulk of the data in the db lives), plus Solr, and I'm trying to untangle it.

I want to add a function to my controller that updates multiple entries in the database but I can't figure it out. I'll post a snippet of a working existing code along with my attempt:

//Controller
==working, existing code===
public function actionUpdateGuide() {
    $this-&gt;requirePostRequest();

    $attr = craft()-&gt;request-&gt;getPost('guide');
    $request = craft()-&gt;MyPlugin_guide-&gt;updateGuide($attr);

    if ($request &amp;&amp; $request-&gt;isSuccessful()) {
        $this-&gt;clearCachedAsset($attr['id'], 'guide');
        $this-&gt;redirectToPostedUrl();
    } else {
        $this-&gt;hydrateInvalidForm($request, $attr);
    }
}

==not-working, my function===   
public function actionPositionGuide() {
    $this-&gt;requirePostRequest();

    $attr = json_decode(craft()-&gt;request-&gt;getPost('guide.json'), true);
    $neworder = array();

    foreach($attr as $row) {
        $guide = array(
            'id' =&gt; $row['name'],
            'position' =&gt; $row['value']
        );

        array_push($neworder, $guide);
    }

    $request = craft()-&gt;MyPlugin_guide-&gt;positionGuides($neworder);


Then

//Service
==working, existing code=== 
public function getGuideLocations($id, $page) {
    $url = $this-&gt;getUrl() . "/" . $id . "/locations?page=$page";
    $response = craft()-&gt;laravel_plugin-&gt;send('get', $url);

    if (!$response-&gt;isSuccessful()) {
        return array("error" =&gt; $response-&gt;getStatusCode(), "msg" =&gt; "get_guide_locations_error");
    }

    return $response-&gt;json();
}

==non-working, my function==
public function positionGuides($attr) {

    foreach($attr as $guide) {
        craft()-&gt;laravel_plugin-&gt;update($attr);
    }
}


I'm confused because I assumed the normal workflow was controller->service->model->database, but this seems to be controller->service->anotherplugin-service.

Looking in the controller for this Laravel plugin, I see:

public function update($id) {
    $guide = Guide::find($id);

    if (is_null($guide)) {
        return 'error';
    }

    $locations = Input::get("locations", array());
    if(!empty($locations)) {
        $locations =  Location::whereIn('id', $locations)-&gt;lists('id');
    }

    $guide-&gt;locations()-&gt;sync($locations);

    $guide = $guide-&gt;fill(Input::all());

    if (!Input::has('image_id')) {
        $guide-&gt;image_id = null;
    }

    return $guide-&gt;save() ? $guide : $guide-&gt;getErrors();
}


And here is the laravel_api model for it:

protected $table = "guides";
protected $fillable = ["name", "city", "type", "image_id", "description", "status", "updated_by", "document", "position"];
protected $dates = ['deleted_at'];
protected $rules = ["name" =&gt; "required"];
protected $appends = array('location_detail');

protected $searchable = ['name', 'description', 'subtitle'];

public function locations()
{
    return $this-&gt;belongsToMany('Location');
}


Any advice would be appreciated.
OK, I managed to figure it out and I'll post the solution for those who run into similar problems.

Essentially, what's happening is Twig template->Plugin controller->Plugin Service->Laravel API->Laravel Controller->Database

The code:

//Plugin controller
public function actionPositionGuide() {
    $this-&gt;requirePostRequest();
    $attr = json_decode(craft()-&gt;request-&gt;getPost('guide.json'), true);
    $neworder = array();
    foreach($attr as $row) {
        $guide = array(
            'id' =&gt; $row['name'],
            'position' =&gt; $row['value']
        );
        array_push($neworder, $guide);
    }
    $request = craft()-&gt;myplugin_guide-&gt;positionGuides($neworder);

}


Then

//Plugin service
public function positionGuides($attr) {
    $url = $this-&gt;getBaseUrl() . "/guides/position";
    return craft()-&gt;mylaravel_api-&gt;send('post', $url, $attr);


}


Then add a route to the Laravel routes.php file

Route::post('guides/position', 'GuidesController@position');


Then the Laravel controller:

public function position() {
    $data = Input::all();
    $response = ["msg" =&gt; "success", "status" =&gt; 200];

    foreach($data as $guide) {

        $oldguide = Guide::find($guide['id']);

        if (is_null($oldguide)) {
            $response = ["msg" =&gt; "error", "status" =&gt; 500];
        }

        $oldguide-&gt;position = $guide['position'];

        $oldguide-&gt;save() ? $oldguide : Log::debug($oldguide-&gt;getErrors());
    }

    return Response::json($response["msg"], $response["status"]);
}


Error handling is not great but if anyone has suggestions for improvement, I'm all ears.