Mirich
Mirich

Reputation: 351

How to show balance in the view

I want to show balance in the view, that is, there is a column called Balance in user table and I would like to display the value of that column in the view. Please guys spare me some time The view:

@extends('layouts.app')
@section('content')
<h1>Personal Finance</h1>
<p class="p-2 text-dark" >Balance:{{Form::label($balance)}}</p>
<a href="/personal/create" class="btn btn-primary">Create</a>
<br>
@stop

The controller:

public function index()
    {
        $user_id=auth()->user()->id;
        $user=User::find($user_id);
        $balance=$user->balance;
        return view('personal.index', compact('personal','balance'));

    }

Upvotes: 0

Views: 54

Answers (2)

Afraz Ahmad
Afraz Ahmad

Reputation: 5386

You are doing a mistake. You are searching a logged in user twice

First change this

$user_id=auth()->user()->id; $user=User::find($user_id);

to $user=auth()->user() because it will give you logged in user

Then add this line in the blade view:

<p>{{$balance}}</p>

Upvotes: 1

Sunil kumawat
Sunil kumawat

Reputation: 804

Simply you can use

public function index()
    {
        $user_id=auth()->user()->id;
        $user=User::findOrFail($user_id);
        return view('personal.index', compact('personal','user'));

    }

Then add this line in the view file

<p>{{$user->balance}}</p>

Upvotes: 2

Related Questions