Eloquent, Make items upgradable

Posted 8 months ago by Stank0V01

Hello i have some idea to ranks be upgradable! So i have categories products and orders!

So i want to make something like this

First i will give you some code and migrations:

Product structure:

        Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('description');
            $table->unsignedInteger('recommended');
            $table->integer('price');
            $table->string('image');
            $table->unsignedInteger('required_product_id')->nullable();
            $table->unsignedInteger('max_buys');
            $table->integer('discount')->nullable();
            $table->timestamps();
        });

Orders structure:

        Schema::create('orders', function (Blueprint $table) {
            $table->increments('id')->unique();
            $table->integer('product_id');
            $table->integer('user_id');
            $table->timestamps();
        });

So i will explain what column : required_product_id column must have id of product that must purchase first to purchase it! Second is max_buys

if max_buys is 1 product can be buyable only once , if its 0 it can purchased many times that i want.

If you want some example: http://iplexmc.eu/p/1 (It will ask you for username enter some random username and click here http://prntscr.com/k6qzby

(All products are in category so it is hasMany rel)

CategoriesController.php

namespace App\Http\Controllers;

use App\Product;
use Illuminate\Http\Request;
use App\Category;
use App\User;
use App\Order;
use Illuminate\Support\Facades\DB;

class CategoriesController extends Controller
{
    /**
     * @param Category $category
     * @param User $user
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function showProducts(Category $category, User $user)
    {
        $products = $category->products();


        return view('products.category',['products'=>$products]);


    }
}

Please help me , i don't know how to do that (I want products var to return and producta that be only once purchased) (When user purchase rank that is onlyOnce it will removed from the list)

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.