php - How to Show user Order History in Laravel 5.4 -


i have 2 table of order's
orders table

schema::create('orders', function (blueprint $table) {             $table->increments('id');             $table->string('fname');             $table->string('lname')->nullable();             $table->string('address1');             $table->string('address2')->nullable();             $table->string('city');             $table->string('region');             $table->string('postcode');             $table->string('country');             $table->string('phone');             $table->string('total');             $table->string('paymentmode');             $table->string('randomid');             $table->integer('user_id')->unsigned();             $table->foreign('user_id')->references('id')->on('users')                         ->ondelete('restrict')                         ->onupdate('restrict');             $table->timestamps();         }); 

and productorders

schema::create('productorders', function (blueprint $table) {             $table->increments('id');             $table->string('name');             $table->string('qty');             $table->integer('order_id')->unsigned();             $table->foreign('order_id')->references('id')->on('orders')                         ->ondelete('cascade')                         ->onupdate('restrict');             $table->timestamps();         }); 

here order model

<?php  namespace app;  use illuminate\database\eloquent\model;  class order extends model {        public function user(){        return $this->belongsto('app\user');      }      public function order(){           return $this->hasmany('app\productorder');      } } 

here productorder model

<?php  namespace app;  use illuminate\database\eloquent\model;  class productorder extends model {     public function order(){        return $this->belongsto('app\order');      } } 

orders has many productorders , productorders belongstoo order because there multi product each orders

order completed want show order history ordered user's

thanks

into users model, add following:

public function orders(){   return $this->hasmany('\app\orders'); } 

now, controller, may call

auth::user()->orders(); 

this return orders collection user. may compact view , format like. may use eager/lazy load additional detais on order. here may find additional info on that: https://laravel.com/docs/5.4/eloquent-relationships


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -