Home >Backend Development >PHP Tutorial >How Do I Access Data Passed to a Laravel Blade View?
Accessing Data Passed to View in Laravel
When attempting to utilize the array $posts within a Blade view, you may encounter an error indicating that it's not defined. This occurs because the data needs to be explicitly passed to the view using the with method.
return View::make('blog')->with('posts', $posts);
By using the with method, you assign the $posts array to the variable posts, making it accessible within the Blade view. You can then safely iterate over it using @foreach:
@foreach ($posts as $post) <!-- Your code here --> @endforeach
The above is the detailed content of How Do I Access Data Passed to a Laravel Blade View?. For more information, please follow other related articles on the PHP Chinese website!