A lot or commented code in that view template….
Mar 3, 2022
17
Level 9
syntax error, unexpected '{' (View: ...\views\livewire\account-show.blade.php)
Livewire Component
<?php
namespace App\Http\Livewire;
use App\Models\Account;
use App\Models\AccountTransaction;
use Livewire\Component;
use Livewire\WithPagination;
use Symfony\Component\Console\Descriptor\Descriptor;
class AccountShow extends Component
{
use WithPagination;
public $sortBy = 'created_at';
public $sortAsc = false;
public $search = '';
public $perPage = 10;
public $account;
public $accountTransactions;
//public $runningBalance = [];
public $runningBalance;
// Table Sort
public function sortBy($field)
{
if($field == $this->sortBy){
$this->sortAsc = !$this->sortAsc;
}
$this->sortBy = $field;
}
public function updatingSearch()
{
$this->resetPage();
}
public function mount(Account $account)
{
$this->account = $account ?? new Account();
//Selected Account's accounttransactions
$this->accountTransactions = $account->accountTransactions;
// foreach ($this->accountTransactions as $accountTransaction) {
// //dd($accountTransaction->id);
// $this->runningBalance[$accountTransaction->id] += $accountTransaction->amount;
// }
foreach ($this->accountTransactions as $accountTransaction) {
$this->runningBalance += $accountTransaction->amount;
}
}
public function render()
{
$accountTransactions = AccountTransaction::with('account', 'transaction')
->where('account_id', $this->account->id)
->orderBy($this->sortBy, $this->sortAsc ? 'ASC' : 'DESC')
->paginate($this->perPage);
return view('livewire.account-show', [
'accountTransactions' =>$accountTransactions,
]);
}
}
<div class="flex flex-col">
<div class="xl:flex xl:items-center xl:justify-between xl:mx-4 xl:mb-2">
<p class="text-3xl ..."></p>
<div class="xl:w-4/6">
<div class="flex flex-col space-y-2 xl:space-x-2 xl:flex xl:flex-row xl:space-y-0">
<select wire:model="perPage"
class="block border-gray-300 rounded-md shadow-sm 1/6 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
<option>10</option>
<option>100</option>
<option>1000</option>
</select>
</div>
</div>
</div>
<div class="overflow-x-auto xl:-my-2 sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<table class="min-w-full text-center divide-y divide-gray-200 table-fixed">
<thead class="font-bold text-gray-700 bg-gray-50">
<th scope="col" class="w-3/12 px-6 py-3 text-xs tracking-wider uppercase">
<div class="flex items-center justify-center">
<div class="flex items-center justify-center">
transaction date
</div>
</div>
</th>
<th scope="col" class="w-3/12 px-6 py-3 text-xs tracking-wider uppercase">
<div class="flex items-center justify-center">
<div class="flex items-center justify-center">
description
</div>
</div>
</th>
<th scope="col" class="w-2/12 px-6 py-3 text-xs tracking-wider uppercase">
<div class="flex items-center justify-center">
<button wire:click="sortBy('amount')" class="text-xs font-bold tracking-wider uppercase">amount</button>
<x-sort-icon icon sort-field="amount" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th scope="col" class="w-4/12 px-6 py-3 text-xs tracking-wider uppercase">
<div class="flex items-center justify-center">
<div class="flex items-center justify-center">
running balance
</div>
</div>
</th>
</thead>
<tbody class="text-left bg-white divide-y divide-gray-200">
@foreach ($accountTransactions as $accountTransaction)
<tr>
<td class="px-6 py-2 text-sm text-gray-500 border-2 border-gray-200 whitespace-nowrap text-center">
{{ $accountTransaction->created_at }}
</td>
<td class="px-6 py-2 text-sm text-gray-500 border-2 border-gray-200 whitespace-nowrap text-center">
{{ $accountTransaction->description }}
</td>
<td class="px-6 py-2 text-sm text-gray-500 border-2 border-gray-200 whitespace-nowrap text-right">
{{ number_format($accountTransaction->amount, 2) }}
</td>
<td class="px-6 py-2 text-sm text-gray-500 border-2 border-gray-200 whitespace-nowrap text-center">
{{ number_format($runningBalance.{{ $index }}.amount, 2) }}
</td>
<td class="px-6 py-2 text-sm text-gray-500 border-2 border-gray-200">
<div class="h-10 overflow-x-hidden overflow-y-auto">
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="mx-4 mt-4">
{{ $accountTransactions->links() }}
</div>
</div>
</div>
Account Model
public function accountTransactions()
{
return $this->hasMany('App\Models\AccountTransaction', 'account_id');
}
Table: account_transaction
Columns:
id bigint(20) UN AI PK
account_id int(11)
transaction_id int(11)
resource_id int(11)
comp_id int(11)
description varchar(255)
amount int(11)
created_at timestamp
updated_at timestamp
deleted_at timestamp
Please or to participate in this conversation.