Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. Schema::create('transactions', function (Blueprint $table) {
  2. $table->bigIncrements('id');
  3. $table->bigInteger('from_id')->unsigned();
  4. $table->foreign('from_id')->references('id')->on('users');
  5. $table->bigInteger('to_id')->unsigned();
  6. $table->foreign('to_id')->references('id')->on('users');
  7. $table->integer('Amount');
  8. $table->enum('TransactionType', ['Credit', 'Debit']);
  9. $table->enum('Status', ['Completed', 'Incomplete']);
  10. $table->timestamps();
  11. });
  12.  
  13. Schema::create('users', function (Blueprint $table) {
  14. $table->bigIncrements('id');
  15. $table->string('name');
  16. $table->string('email')->unique();
  17. $table->string('password');
  18. $table->string('AccountNumber')->unique();
  19. $table->rememberToken();
  20. });
  21.  
  22. class Transactions extends Model{
  23. public function users(){
  24. return $this->belongsTo('AppUsers');
  25. }
  26. }
  27.  
  28. <?php
  29.  
  30. namespace App;
  31.  
  32. use IlluminateNotificationsNotifiable;
  33. use IlluminateContractsAuthMustVerifyEmail;
  34. use IlluminateFoundationAuthUser as Authenticatable;
  35.  
  36. class User extends Authenticatable{
  37. use Notifiable;
  38.  
  39. protected $fillable = [
  40. 'name', 'email', 'password', 'Amount',
  41. ];
  42.  
  43. public function transactions(){
  44. return $this->hasMany('AppTransactions');
  45. }
  46. }
  47.  
  48. public function Transactions(){
  49. $Trans = Transactions::all();
  50. return view('Admin.TranAdmin')->with(['title'=>'Transaction History ', 'Trans'=>$Trans]);
  51. }
  52.  
  53. <?php $no = 1; ?>
  54. @foreach ($Trans as $Tran)
  55. <tr>
  56. <td>{{ $no++ }}</td>
  57. <td>{{ $Tran->to_id }}</td>
  58. <td>{{ $Tran->from_id->name }}</td>
  59. <td>{{ $Tran->status }}</td>
  60. <td>{{ $Tran->created_at->format('F jS, Y')}}</td>
  61. <td></td>
  62. </tr>
  63. @endforeach
  64.  
  65. class Transactions extends Model{
  66. public function from(){
  67. return $this->belongsTo('AppUsers','from_id', 'id');
  68. }
  69.  
  70. public function to(){
  71. return $this->belongsTo('AppUsers', 'to_id', 'id');
  72. }
  73.  
  74. //maybe you dont need the user relationship at all
  75.  
  76. }
  77.  
  78. $transaction->to->name;
  79. $transaction->from->name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement