Home  >  Q&A  >  body text

"Laravel 8 + Inertia does not display variables correctly"

I'm actually struggling with passing data to a GET request page, I'm trying to pass data from the database to the Dashboard.vue component (using Laravel 8 Inertia.js stack)

But nothing happened, why?

Controller component:

public function index(Request $request)
{
        return Inertia::render('Dashboard', [
            'percentages' => $percentages = DB::table('profits')->where('user_id', $request->user()->id)->sum('percentage'),
            'profits' => $profits = DB::table('profits')->where('user_id', $request->user()->id)->sum('total_profit'),
            ]);
}

front end:

<div class="container">
                    <div class="row">
                        <div class="col-sm-5 text-center fund-profits">
                          {{profits}}
                        </div>
                        <div class="col-sm-2 text-center nomad-separator">
                            |
                        </div>
                        <div class="col-sm-5 text-center fund-profits">
                          {{percentages}}
                        </div>
                    </div>
   </div>
    
        <script>
            import JetApplicationLogo from './../Jetstream/ApplicationLogo'
        
            export default {
                props: ['percentages', 'profits'],
                components: {
                    JetApplicationLogo,
                },      
            }
        </script>


P粉317679342P粉317679342349 days ago598

reply all(1)I'll reply

  • P粉151466081

    P粉1514660812023-11-06 09:28:14

    I encountered a similar problem yesterday. I used inertia when rendering again in routes/web.php and I think an override occurred. Try not using inertia in your routes, worked for me.

    reply
    0
  • Cancelreply