Cast Array to an Object in Controller and then pass to view in laravel

You can change the array to an object using the (object) method in your controller and then you can pass the value in the view file. You can display the view file using $array->title syntax.

Answers 1
  • Change array to object in controller and access in view file in laravel

    Route::get('/array-to-object', function(){
        $array = array('title' => 'hello world');
        $object = (object)$array;
        return view('index')->with(compact('object'));
    {{ $object->title }}
  • Back to code snippet queries related laravel