Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function index()
- {
- return ProductResource::collection(Product::with('inventories')->paginate(25));
- }
- class Product extends Model
- public function inventories(){
- return $this->belongsToMany('AppInventory','inventory_product')->withPivot('price','stock')->withTimestamps();
- }
- class Inventory extends Model
- public function products(){
- return $this->belongsToMany('AppProduct','inventory_product')->withPivot('price','stock')->withTimestamps();
- }
- public function toArray($request)
- {
- return [
- 'id'=>$this->id,
- 'name'=>$this->name,
- 'description'=>$this->description,
- 'short_description'=>$this->short_description,
- 'category'=>$this->category,//category_id
- 'url'=>$this->url,
- 'image'=>$this->image,
- 'relevant'=>$this->relevant,
- 'month'=>$this->month,
- 'price'=>$this->price,
- 'stock'=>$this->stock
- ];
- }
- Schema::create('inventories', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name');
- $table->unsignedInteger('city_id');
- $table->timestamps();
- $table-> foreign('city_id')->references('id')->on('cities')->onDelete('cascade');
- });
- Schema::create('products', function (Blueprint $table) {
- $table->increments('id');
- $table ->string('name');
- //$table ->integer('stock');
- $table ->string('description');
- $table ->string('short_description');
- $table ->unsignedInteger('category');//category_id
- //$table ->integer('price');
- $table ->string('url');
- $table ->string('image');
- $table ->boolean('relevant');
- $table ->boolean('month');
- $table->timestamps();
- $table-> foreign('category')->references('id')->on('categories')->onDelete('cascade');
- });
- $table->increments('id');
- $table->integer('inventory_id')->unsigned();
- $table->integer('product_id')->unsigned();
- $table ->integer('price');
- $table ->integer('stock');
- $table->timestamps();
- $table-> foreign('inventory_id')->references('id')->on('inventories')->onDelete('cascade');
- $table-> foreign('product_id')->references('id')->on('products')->onDelete('cascade');
- {
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement