first of all, I am very sorry if this has already been answered. This is a question I've been breaking my head on, and can't seem to figure out any proper solution.
What I am trying to do is retrieve data from my database making use of a Laravel controller, and send this data to my React component.
So for example, I have a table filled with movies. In my controller, I retrieve all these movies using:
public function getMovies()
{
return Movie::select('id', 'name', 'description', 'image')->get();
}
Then, I want to send this list of movies to my React component, where I want to go over a foreach to display all of them. How does one do this? My apologies for this question. I am just starting to learn how to work with React to work on a project.
First just change :
public function getMovies()
{
return Movie::select('id', 'name', 'description', 'image')->get();
}
To :
public function getMovies()
{
$movies = Movie::all();
return ('yourview', compact(['movies']));
}
Then, In your blade view just use
@foreach ($movies as $movie)
<p>{{ $movies->name }}</p>
<p>{{ $movies->description }}</p>
<p>{{ $movies->image }}</p>
@endforeach