dimanche 4 février 2018

Get or fetch Latest or last create multiple rows in laravel

I am in need of desperate help. I am newbie to laravel and programming.

I have a sales controller which fetch multiple records from form using jquery and select.

Sales Store controller looks like:

    for ($i=0; $i < count($request['product_id']); ++$i) 
     {
     $sales= new Sale;        
                $sales->product_id = $request['product_id'][$i];
                $sales->qty= $request['qty'][$i];
                $sales->user_id = Auth::user()->id;
                $sales->save(); 
                $product = new Product;
                $product->where('id', '=', $request['product_id'][$i])->decrement('stock', $request['qty'][$i]);

            }

this code is working perfectly fine.

Now the scenario is that I want to fetch these last created specific records to send it somehow to other page or as an invoice. Any help will be greatly appreciated on how to achieve this? Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire