samedi 7 juillet 2018

Laravel 5.6 Returning API Resource Errors

In Laravel 5.6, I have a controller method that is passing a query through an API resource. I can return $model and see the transformed data but when I try to pass it to a view, I get this error:

htmlspecialchars() expects parameter 1 to be string, object given

public function model($id)
    {
        $raw = AdcModel::whereId($id)
            ->with('ascend', 'bd_lead', 'modeler')
            ->first();
        $model = new ModelsResource($raw);
        //return $model;


        return view('model', compact('model'));
    } // end function

I realize that the API Resource is intended to be used in an API but isn't there a way to just pass it to the view and avoid a json call once the view loads?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire