Reputation: 351
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
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
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