Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Schema::create('transactions', function (Blueprint $table) {
- $table->bigIncrements('id');
- $table->bigInteger('from_id')->unsigned();
- $table->foreign('from_id')->references('id')->on('users');
- $table->bigInteger('to_id')->unsigned();
- $table->foreign('to_id')->references('id')->on('users');
- $table->integer('Amount');
- $table->enum('TransactionType', ['Credit', 'Debit']);
- $table->enum('Status', ['Completed', 'Incomplete']);
- $table->timestamps();
- });
- Schema::create('users', function (Blueprint $table) {
- $table->bigIncrements('id');
- $table->string('name');
- $table->string('email')->unique();
- $table->string('password');
- $table->string('AccountNumber')->unique();
- $table->rememberToken();
- });
- class Transactions extends Model{
- public function users(){
- return $this->belongsTo('AppUsers');
- }
- }
- <?php
- namespace App;
- use IlluminateNotificationsNotifiable;
- use IlluminateContractsAuthMustVerifyEmail;
- use IlluminateFoundationAuthUser as Authenticatable;
- class User extends Authenticatable{
- use Notifiable;
- protected $fillable = [
- 'name', 'email', 'password', 'Amount',
- ];
- public function transactions(){
- return $this->hasMany('AppTransactions');
- }
- }
- public function Transactions(){
- $Trans = Transactions::all();
- return view('Admin.TranAdmin')->with(['title'=>'Transaction History ', 'Trans'=>$Trans]);
- }
- <?php $no = 1; ?>
- @foreach ($Trans as $Tran)
- <tr>
- <td>{{ $no++ }}</td>
- <td>{{ $Tran->to_id }}</td>
- <td>{{ $Tran->from_id->name }}</td>
- <td>{{ $Tran->status }}</td>
- <td>{{ $Tran->created_at->format('F jS, Y')}}</td>
- <td></td>
- </tr>
- @endforeach
- class Transactions extends Model{
- public function from(){
- return $this->belongsTo('AppUsers','from_id', 'id');
- }
- public function to(){
- return $this->belongsTo('AppUsers', 'to_id', 'id');
- }
- //maybe you dont need the user relationship at all
- }
- $transaction->to->name;
- $transaction->from->name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement