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
- Send post data from controller to view
- Json encode method in laravel
- Class 'App\Rules\Hash' not found in Laravel
- Create model with migration and seeder
- Laravel 7 login error message not showing
- How to restore multiple records after soft-deletes in Laravel
- Get current month records in laravel 7/8
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- How to create belongstomany relation using custom name on custom pivot table
- How to display validation error in laravel
- Route prefix with auth middleware in laravel
- Laravel append URI in route
- If condition in Laravel 9
- Conditional where clause in Laravel
- How to get last month records in Laravel
- How to upload local Laravel project to server ?
- How to get all route list
- Target class [admin] does not exist.
- OrderBy on Eloquent relationships method in Laravel
- How to return error message from controller to view in laravel
- How to Access Array in blade laravel
- Laravel order by date not working
- Rename Pivot Table in Laravel
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table