Cast Array to an Object in Controller and then pass to view in laravel
Cast Array to an Object in Controller and then pass to view in laravel
In this tutorial, we will try to find the solution to "Cast Array to an Object in Controller and then pass to view in laravel" through programming.
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.-
Change array to object in controller and access in view file in laravel
//routes\web.php Route::get('/array-to-object', function(){ $array = array('title' => 'hello world'); $object = (object)$array; return view('index')->with(compact('object')); }); //resources\views\index.blade.php {{ $object->title }}
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Get latest record by created at in Laravel
- Laravel create multiple records in Pivot table
- Order by multiple columns in Laravel
- Laravel URL validation not working
- How to create laravel project using composer
- Get ids in array from users table
- How to get route name on visit URL in laravel
- On delete set foreign id column value null using migration in laravel 8
- Remove array keys and values if it does not exist in other array in Laravel
- Display success message in laravel
- Class 'App\Rules\Hash' not found in Laravel
- How to add a key value pair to existing array in laravel
- How to get last record from object collection in laravel
- Store logged in user details in session and display in view in laravel
- First and last item of the array using foreach iteration in laravel blade
- Use withCount() to get total number of records with relationship
- How to use more than one query scope in Laravel
- Drop foreign key column in Laravel using migration
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- How to check record exist or not in relationship table
- Skip first n record and display rest records in laravel view
- How to get database name in Laravel 9 ?
- Route not defined in Laravel
- Create a record if not exist in laravel
- How to check find method executed successfully in laravel