"Laravel 8 + Inertia does not display variables correctly"
P粉317679342
P粉317679342 2023-11-05 12:01:19
0
1
660

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粉317679342
P粉317679342

reply all(1)
P粉151466081

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template