Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Pass a laravel controller model to a react component

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!