mardi 18 juillet 2017

Select From Two/Three Table using Eloquent Controller Laravel 5

I'm working on ERP/Inventory System using Laravel 5.4 with Adminlte. I've a table call stocks that has the product_id, category_id,supplier_id as FK to product, category and supplier table. Stock table. I've the function in my controller.

public function getStockList()
{
   $stock = DB::table("stocks")->pluck("product_id","product_id")->all();
    return view('shop.shop')->with(['stock' => $stock,]);
   }
public function getBrandList(Request $request)
{
    $brands = DB::table("stocks")
        ->where("product_id",$request->product_id)
        ->pluck("brand_id","brand_id");
    return response()->json($brands);
}
public function getSupplierList(Request $request)
{
    $suppliers = DB::table("stocks")
        ->where("brand_id",$request->brand_id)
        ->pluck("supplier_id","supplier_id");
    return response()->json($suppliers);
}

After $stock = DB::table("stocks")->pluck("product_id","product_id")->all(); I want another query that will now SELECT name from PRODUCT where id = product_id and also FOR

$brands = DB::table("stocks")->where("product_id",$request->product_id)->pluck("brand_id", "brand_id");

I want to SELECT name FROM BRAND where id =brand_id

MY php.BLADE

<div class="panel panel-default">
                <div class="panel-heading">Dependent country state city dropdown using ajax in PHP Laravel Framework</div>

                <div class="panel-body">
                    <div class="form-group">
                        <label for="title">Select Product:</label>
                        {!! Form::select('stock', ['' => 'Select'] +$stock,'',array('class'=>'form-control','id'=>'country','style'=>'width:350px;'))!!}

                    </div>
                    <div class="form-group">
                        <label for="title">Select Brand:</label>
                        <select name="brand" id="brand" class="form-control" style="width:350px">
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="title">Select Supplier:</label>
                        <select name="supplier" id="supplier" class="form-control" style="width:350px">
                        </select>
                    </div>
                </div>

PLESE NOTE I tried to $products = DB::table("products")->pluck("name")->where('id', $stock); return view('shop.shop')->with([ 'stock' => $stock, 'products' => $products]); BUT IT DOESN'T WORK!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2uzQvyo
via IFTTT

Aucun commentaire:

Enregistrer un commentaire