EMfinanga

EMfinanga

Member Since 1 Month Ago

Experience Points 2,110
Experience Level 1

2,890 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

23 May
1 day ago

EMfinanga left a reply on INVOICE NUMBER IS NOT INCREMENT

@JOHNBRAUN - So what can i do from there?

EMfinanga started a new conversation INVOICE NUMBER IS NOT INCREMENT

I tried to generate the invoice number, but its is not increment as you can see the code below

How can i do to increment after check the last Invoice number

                    foreach($request->product_name as $Customeraddress => $i) {

     //get last record
            $record = Customer::latest()->first();
            $expNum = explode('-', $record->invoice_number);

      // dd($expNum);
       //check first day in a year
            if ( date('l',strtotime(date('Y-01-01'))) ){
                $nextInvoiceNumber = date('m').'PACL'.'-0001';
            } else {
      //increase 1 with last invoice number
                $nextInvoice = $expNum[0].'-'. $expNum[1]+1;
            }

             // $invoiceNumber = 'PACL-' . date('m') . '/' . '0001';



            Customer::create([
                'customer_id'    => $request->input('clientName'),
                'product_name'   => $request->product_name[$Customeraddress],
                'quantity'       => $request->quantity[$Customeraddress],
                'price'          => $request->price[$Customeraddress],
                'amount'         => $request->amount[$Customeraddress],
                'invoice_number' => $nextInvoice,
            ]);
        }

EMfinanga left a reply on Generate Invoice Number

I need on the same table

EMfinanga left a reply on Generate Invoice Number

What if two users are creating invoices simultaneously? Once they save, the numbers will be different if invoice number is a unique identifier.?

And we do need to check the last invoice ? And create new one ? Or

22 May
2 days ago

EMfinanga started a new conversation Generate Invoice Number

someone can get me an idea to generate the Invoice number,

fisrts need to start with PACL-Mothly/001

Exmple: PACL-05/001, PACL-05/002........PACL-06/003 and so on

my code below:

            if ($validator->passes()) {

        // $clientName=Customeraddress::find($request->id);
        // if(count($request->product_name) > 0)
        // {
            foreach($request->product_name as $Customeraddress=>$v){
                $data2=array(
                    'customer_id'=>$request->input('clientName'),
                    'product_name'=>$request->product_name[$Customeraddress],
                    'quantity'=>$request->quantity[$Customeraddress],
                    'price'=>$request->price[$Customeraddress],
                    'amount'=>$request->amount[$Customeraddress],
                );

                Customer::create($data2);

EMfinanga left a reply on Find($id) Instead Of Find(1,3,4....)

@NAKOV - this is my form,, i did not put hidden

            <select name="clientName" class="form-control payment_status">
                                  <option selected>~~~Choose payment Status~~~</option>
                                  @foreach($customerview as $customer)
                                  <option  value="{{$customer->id}}">{{$customer->clientName}}</option>
                                  @endforeach
                                 
                               </select>
                       </div>

EMfinanga left a reply on Find($id) Instead Of Find(1,3,4....)

@NAKOV - no, as you can check the full store function code

             public function store(Request $request)

         {
    
    $validator = Validator::make($request->all(), [
        'clientName' => 'required',
        // 'payment_status' => 'required',
        'product_name' => 'required',
        'quantity' => 'required',
        'price' => 'required',
        'amount' => 'required',

    ]);

    if ($validator->passes()) {

        $clientName=Customeraddress::find($id);
        // if(count($request->product_name) > 0)
        // {
            foreach($request->product_name as $Customeraddress=>$v){
                $data2=array(
                    'customer_id'=>$clientName->id,
                    'product_name'=>$request->product_name[$Customeraddress],
                    'quantity'=>$request->quantity[$Customeraddress],
                    'price'=>$request->price[$Customeraddress],
                    'amount'=>$request->amount[$Customeraddress],
                );

                Customer::create($data2);
                  //update stocks
                // $product = Product::find(id);
                // $stock = Stock::where('pid', $product->id);
        //               $stock->decrement('quantity', $stock->quantity);
             }  
                 // }
        return redirect('customersaleview')->with('success', 'Successfully Stored');
        
    }
    return Response::json(['errors' => $validator->errors()]); 

     }

EMfinanga started a new conversation Find($id) Instead Of Find(1,3,4....)

i select my customer name from DB as well, but when i put find($id), i get the error "Undefined Variable id"

what is the issue ?

my code

            $clientName=Customeraddress::find($id);
        // if(count($request->product_name) > 0)
        // {
            foreach($request->product_name as $Customeraddress=>$v){
                $data2=array(
                    'customer_id'=>$clientName->id,
                    // 'payment_status'=>$request->payment_status[$Customeraddress],
                    'product_name'=>$request->product_name[$Customeraddress],
                    'quantity'=>$request->quantity[$Customeraddress],
                    'price'=>$request->price[$Customeraddress],
                    'amount'=>$request->amount[$Customeraddress],
                );

                Customer::create($data2);
20 May
4 days ago

EMfinanga started a new conversation Insert Multiple Data Into Database

Someone can get me an ideas, how can i insert multiples data into DB.

I have two table customer-Details and Order tables

So i want to select all customer name and insert into order table depends to orders.

17 May
1 week ago

EMfinanga left a reply on Create Once And Continuous Update Balance Amount Column

@JLRDW - ok noted, but what if you want fetch the latest amount which created yesterday?

16 May
1 week ago

EMfinanga started a new conversation Create Once And Update One Column

i want to update the balance after created,

example when the sales is performing the balance is decrease or increase, so i want to update when the sales is updating, not to create multiple rows again

my code which create the balance

    <?php $closedbalance=($totalpayment+$totalAmount)-$totalexpenses; 

          $balance = \App\Totalbalance::create([
        'balance' => $closedbalance, 

      ]);

       ?>

EMfinanga left a reply on HOW CAN I SAVE THE PREVIOUS/YESTERDAY BALANCE

@MTHOMAS - it works well, but when you refresh the page it created again, can we create once and update once the data is update? without create multiple rows?

what i have done

            <?php $closedbalance=($totalpayment+$totalAmount)-$totalexpenses; 

        $balance = \App\Totalbalance::create([
        'balance' => $closedbalance, 

       ]);

       ?>

EMfinanga left a reply on Table Relationship

@DEVFREY - //Mikopo $mikopo = DB::table('customers')->select(DB::raw('*'),DB::raw('sum(amount) as totalM')) ->whereRaw('Date(created_at) = CURDATE()') ->groupby('id') ->get();

              $totalmikopo=$mikopo->sum('totalM');
     return view('report.reportview',compact('sales','Expenses','totalexpenses','totalAmount','customersaleview','totalAmountcustomer','mikopo','totalmikopo','totalpayment','payment','paymentcheq','totalpaymentcheq'));

EMfinanga started a new conversation Table Relationship

i have two table is related, and have the query display all table from one table, and i want to add and view the Client name ,, i want to use the model to get the client name

my model is

      class Customer extends Model

{ protected $table='customers';

protected $fillable=['customer_id','payment_status','product_name','quantity','price','amount'];

 public function customeraddress()
{
    return $this->belongsTo('App\Customeraddress');
}

}

on my view page

         @foreach($mikopo as $key=>$data)
     <tr>
   <td>{{ ++$key }}</td>
    <td>{{$data->customeraddress->clientName}}</td>

i get thus Error

    Undefined property: stdClass::$customeraddress

i want to get the name also from another table

15 May
1 week ago

EMfinanga left a reply on Delete Data In Multiple Tables

@RESPECT - can you show an Examples for those options

EMfinanga started a new conversation Delete Data In Multiple Tables

i want to delete, all data in multiple table where id is selected by click the button,

i have two table is related

EMfinanga started a new conversation HOW CAN I SAVE THE PREVIOUS/YESTERDAY BALANCE

suppose you have an closed balance for Today= 100usd, and you want to use this balance for tomorrow as per formula below.

to get Today Closed balance the formula looks like:

              todayClosedBalnce=   {{number_format(($totalpayment+$totalAmount)-$totalexpenses,2)}}

to get Closed balance for tomorrow the formula looks like:

{{number_format(($totalpayment(current)+$totalAmount(current)+YesterdayClosedBalnce)-$totalexpenses,2)}}

how can i save the yestaday balance then i will add for next day

EMfinanga left a reply on Select All Data And Created Today

@KEVINBUI - i just modify the code and its work fine

$paymentview= Payment::where('payment_status', 'CASH') // ->select(DB::raw('sum(amount) as totalAmount')) ->whereRaw('Date(created_at) = CURDATE()') ->groupby('id') ->get(); $totalpayment=$paymentview->sum('amount');

// dd($paymentview); return view('payment.paymentmikopo',compact('paymentview','totalpayment'));

EMfinanga started a new conversation Select All Data And Created Today

i want to select all data where payment_status='Cheq' and created today

14 May
1 week ago

EMfinanga left a reply on Get All Data With SUM Of Today And Sum Of Yesterday In Same Query

this is what i want to archive on the below formula in dail report

              formula for Closed balance =cash sales(per day)+cash received(customer)- expenses

and tomorrow we need to have something like this

          closed balance(2moro)=closed balance(yesterday)+cash 
             sales+ cash received(customer)-expenses
13 May
1 week ago

EMfinanga left a reply on ROLES AND PERMISSION PACKAGE IN LARAVEL

@JLRDW - im stacked on migration step,

EMfinanga left a reply on PRINT PDF, HTML To DomPdf

@BEKASKAKI - send your email ID here emma4082@gmail.com or whatsapp +255719260602

EMfinanga left a reply on PRINT PDF, HTML To DomPdf

@BEKASKAKI - can i give my TeamViewer, then you can where im stacked

EMfinanga left a reply on ROLES AND PERMISSION PACKAGE IN LARAVEL

@FRASERK - I can not able to setup this package as well

EMfinanga started a new conversation ROLES AND PERMISSION

i need assistance to install spatie role and permission in my laravel project

kindly can someone assist me on this in case you need a TeamViewer emma4082@gmail.com

EMfinanga left a reply on Get All Data With SUM Of Today And Sum Of Yesterday In Same Query

@TRAY2 - which something along the line, can you arrange like above code?

EMfinanga left a reply on PRINT PDF, HTML To DomPdf

i tried this code and it dowload the last pdf when i click export button?

why its coming old download file? and not new file pdf

               $pdf = PDF::loadView('report.printreport',compact('sales','Expenses','totalexpenses',
             'totalAmount','customersaleview','totalAmountcustomer',
          'mikopo','totalmikopo','payment','totalpayment'));
// If you want to store the generated pdf to the server then you can use the store function
$pdf->save(storage_path().'_filename.pdf');
// Finally, you can download the file using download function
return $pdf->download('printreport.pdf');
12 May
1 week ago

EMfinanga left a reply on Get All Data With SUM Of Today And Sum Of Yesterday In Same Query

@TRAY2 - my table is looks like this

                      'address_id','product_name','quantity','price','amount'

                   $table->increments('id');
                 $table->integer('address_id')->unsigned();
               $table->string('product_name');
              $table->integer('quantity');
             $table->integer('price');
             $table->integer('amount');
             $table->timestamps();
            $table->foreign('address_id')->references('id')->on('addressitems');

EMfinanga left a reply on Select Customer From Database And Insert Into Another Table Will Multiple Data

my base concept is this

First : i want to create customer into DB second: i want to create the sales base on order quantity third: i want to make a payment regards to his order

Example : customer need three or two items, then i select the customer and input their items and save it,, after that on the next time i will select that customer and input the payment as per customer ID

so i need this relationship on the below tables

customerlist customerOrder customerpayment

EMfinanga left a reply on Get All Data With SUM Of Today And Sum Of Yesterday In Same Query

@TRAY2 - this one

            $sales = DB::table('Sales')->select(DB::raw('*'),DB::raw('sum(amount) as totalAmount'))
              ->whereRaw('Date(created_at) = CURDATE()')
              ->groupby('id')
              ->get();

              $totalAmount=$sales->sum('totalAmount');

EMfinanga left a reply on Select Customer From Database And Insert Into Another Table Will Multiple Data

@TRAY2 - i passing an Array from the form as you can see my form below

                <td>
                                                    <select name="product_name[]" class="form-control product_name">
                                                        <option selected>Choose Product Name....</option>
                                                        @foreach($productview as $product)
                                                        <option  value="{{$product->product_name}}">{{$product->product_name}}</option>
                                                        @endforeach
                                                    </select></td>
                                                    <!-- <input type="text" name="brand[]" class="form-control"></td>  -->   
                                                    <td ><input type="text" name="quantity[]" class="form-control quantity" required=""></td>
                                                    <td><input type="text" name="price[]" class="form-control price"></td>
                                                    <td><input type="text" name="amount[]" class="form-control amount"></td>
                                                    <td><a href="#" class="btn btn-danger remove"><i class="far fa-trash-alt"></i></a></td>
                                                </tr>
                                            </tr>
                                        </tbody>

EMfinanga started a new conversation Get All Data With SUM Of Today And Sum Of Yesterday In Same Query

i want to get All data as usual and sum amount but i want sum of yesterday in same query?

EMfinanga left a reply on How To Print Multiple Tables

@TECHHUNT - Where i can add those code in my controller or ?

EMfinanga left a reply on Select Customer From Database And Insert Into Another Table Will Multiple Data

@TRAY2 - i tried your code and Im get this error

                         Invalid argument supplied for foreach()

and my code looks like this

      foreach($request->items as $item) {
     $orderedItem = new  customers();
    $orderedItem->customer_id = Auth()->id;
    $orderedItem->payment_status = $item->payment_status;
    $orderedItem->product_name = $item->product_name;
    $orderedItem->price = $item->price;
    $orderedItem->amount = $item->amount;
    $orederedItem->quantity = $item->quantity;
    $orederedItem->save();

}

EMfinanga left a reply on PRINT PDF, HTML To DomPdf

@MUSHOOD - can you show me the sample of to load in self-content

EMfinanga left a reply on PRINT PDF, HTML To DomPdf

@BEKASKAKI - i have 3 tables i display in one page

                      @extends('layouts.master')

@section('content')

General Report Today
  </div>
  <div class="card-body">
    <div class="row float-right">

Export PDF

   <!-- dashboard Sumary -->


   <table id="" class="table table-sm table-bordered" style="width:50%">
    <thead>
      <tr>
        <th scope="col">#</th>
        <th scope="col">Discriptions</th>
        <th scope="col">Amount</th>
      </tr>
    </thead>
    <tbody>
      <tr class="table-primary">
        <td>1</td>
        <td>OPEN BALANCE</td>
        <td>{{number_format($totalAmount-$totalexpenses,2)}}</td>
      </tr>
      <tr class="table-success">
        <td>2</td>
        <td>CASH SALES(DAY)</td>
        <td>{{number_format($totalAmount,2)}} Tshs</td>


      </tr>
      <tr>
        <td>3</td>
        <td>CASH RECEIVED(CUSTOMER)</td>
        <td></td>
      </tr>
      <tr class="table-danger">
        <td>4</td>
        <td>EXPENSES (DAY)</td>
        <td>{{number_format($totalexpenses,2)}} Tshs</td>


      </tr>
      <tr class="table-secondary">
       <td>5</td>
       <td>CLOSED BALANCE</td>
       <td>{{number_format($totalAmount-$totalexpenses,2)}}</td>

     </tr>


   </tr>

 </tbody>
   <!-- table one -->
         <table id="example" class="table table-bordered" style="width:100%">
      <thead>
  <tr>
    <th scope="col">#</th>
    <th scope="col">Product Name</th>
    <th scope="col">Invoice No</th>

    <th class="text-right">Quantity</th>
    <th class="text-right">Price</th>
    <th class="text-right">Amount</th>
  </tr>
</thead>
<tbody>
 @foreach($sales as $key=>$data)
 <tr>
  <td>{{++$key }}</td>
  <td>{{ $data->product_name }}</td>
  <td>{{$data->address_id}}</td>
  <td>{{$data->quantity}}</td>
  <td>{{$data->price}}</td>
  <td class="text-right">{{number_format($data->totalAmount,2)}} Tshs</td>
</tr>
@endforeach
 <th colspan="5"> Grand Total</th>
 <!-- <th ></th> -->
 <th class="text-right"><strong>{{number_format($totalAmount,2)}} Tshs</strong></th>
 <!-- <th scope="col"></th> -->
<thead>
  <tr>
    <th scope="col">#</th>
    <th scope="col">Invoice No</th>
    <th scope="col">Customer Name</th>
    <th scope="col">Total Amount</th>
    <th class="text-right">Created date</th>
  </tr>
</thead>
<tbody>
 @foreach($customersaleview as $key=>$data)
 <tr>
  <td>{{ ++$key }}</td>
  <td>{{$data->customer_id}}</td>

  <td>{{ $data->clientName }}</td>
  <td class="text-right">{{number_format($data->totalAmountcustomer,2)}} Tshs</td>
  <td>{{ $data->created_at }}</td>

</tr>
@endforeach
<th colspan="4"> Grand Total</th>
<!-- <th ></th> -->
<th class="text-right">{{number_format($totalAmountcustomer,2)}} Tshs</th>
<!-- <th scope="col"></th> -->
#ID Description Amount @foreach ($Expenses as $expns) {{ $expns->eid }} {{ $expns->description }} {{number_format($expns->amount,2)}} Tshs @endforeach
   <th colspan="2"> Grand Total</th>
   <!-- <th ></th> -->
   <th class="text-right">{{number_format($totalexpenses,2)}} Tshs</th>
   <!-- <th scope="col"></th> -->
 </tr>
     </div>
   </div>

 </div>




 @endsection


 @section('scripts')

@endsection

EMfinanga started a new conversation Select Customer From Database And Insert Into Another Will Multiple Data

I have a invoice form which you can input multiple data based on different input rows

I want to select the name of customer and insert into another table with his multiple data Without to create new or to take lastId.

Example, I have two table customer table and salescustomer table,, in the customer i have the list of customer, and send it to salescustomer with items ordered

Someone can get me the idea in the controller how can looks like

11 May
1 week ago

EMfinanga left a reply on How To Print Multiple Tables

@BOBBYBOUWMANN - so what can i do because i want to convert my html to pdf file then i can print it

EMfinanga started a new conversation PRINT PDF, HTML To DomPdf

how can i convert HTML to PDF document, i have tried the below code but it does not convert to pdf its comes with HTML layout

     // Send data to the view using loadView function of PDF facade
$pdf = 

PDF::loadView('report.printreport',compact('sales','Expenses','totalexpenses','totalAmount','customersaleview','totalAmountcustomer')); // If you want to store the generated pdf to the server then you can use the store function $pdf->save(storage_path().'_filename.pdf'); // Finally, you can download the file using download function return $pdf->download('generalReport.pdf');

10 May
2 weeks ago

EMfinanga left a reply on HOW TO PRINT MULTIPLE TABLES

im using a compact to pass those variable, but i face this error

         fopen(C:\wamp64\www\pacl\storage\fonts/\deb1c6713675f2f8e379a7f27c026d7a.ufm): failed to open stream: No such file or directory

some ca assist on this

EMfinanga left a reply on HOW TO PRINT MULTIPLE TABLES

@BOBBYBOUWMANN - i test to the below code,, how can I Send data to the view using loadView function of PDF facade, if i have more than one fetch data table on my reportview i have 3 tables (sales,Expense, and customer ....so on)

i want to print all those table because is fetch in one page

@bobbybouwmann can you show me regards the codes below how can load, because i ge the error "Undefine variable totalexpenses"

     public function showAll() {

 //sales
          $sales = DB::table('Sales')->select(DB::raw('*'),DB::raw('sum(amount) as totalAmount'))
              ->whereRaw('Date(created_at) = CURDATE()')
              ->groupby('id')
              ->get();

              $totalAmount=$sales->sum('totalAmount');
              
    //expenses
         $Expenses = DB::table('Expenses')->select(DB::raw('*'),DB::raw('sum(amount) as totalAmountexp'))
              ->whereRaw('Date(created_at) = CURDATE()')
              ->groupby('eid')
              ->get();

              $totalexpenses=$Expenses->sum('totalAmountexp');

       //customerlist
       $customersaleview =DB::table('customeraddresses')
             ->join('customers','customers.customer_id','=','customeraddresses.id')
            
              ->select('customers.created_at','customeraddresses.clientName','customers.customer_id',DB::raw('SUM(customers.amount) as totalAmountcustomer'))
              ->whereDate('customers.created_at', Carbon::today()->toDateString())
              ->groupby('customer_id','customers.created_at')
             ->get();
              $totalAmountcustomer=$customersaleview->sum('totalAmountcustomer');

 // Send data to the view using loadView function of PDF facade
  $pdf = PDF::loadView('report.reportview', $Expenses);
  // If you want to store the generated pdf to the server then you can use the store function
$pdf->save(storage_path().'_filename.pdf');
// Finally, you can download the file using download function
return $pdf->download('reportview.report');               

return view('report.reportview')- 

with(compact('sales','Expenses','totalexpenses','totalAmount','customersaleview','totalAmountcustomer','pdf') ); }

EMfinanga left a reply on HOW TO PRINT MULTIPLE TABLES

@BOBBYBOUWMANN - this is fine, BUT what i mean, after display on view page,, how can i have single button of PRINT/EXPORT TO PDF

EMfinanga started a new conversation HOW TO PRINT MULTIPLE TABLES

Some can get me the idea how can i print/export multiple tables which are display in one page

EMfinanga started a new conversation Select All Data And Sum Amount Where Data Created Today

i want to get all data and Sum(amount) as Tamount where data is created today

i tried this code

      $sales = Sales::all()
              ->where('date(created_at) = ?', [Carbon::today()])
              ->get();
    $totalAmount=$sales->sum('amount');

EMfinanga left a reply on How Can I Decrease Stocks Base On Order Quantity

the field name is quantity in stock model

stock mode looks like this

          class Stock extends Model
           {
          protected $table='stocks';

        protected $fillable=['pid','quantity','store'];
        }

EMfinanga left a reply on How Can Update Stocks Table After Done A Sales

@TRAY2 - You can assist me from there if it simple to loop that,, that is what i tried so far

09 May
2 weeks ago

EMfinanga started a new conversation Update Stock Quantity Base On Order

How can loop by foreach to decrement my stock quantity,, the below code is decrement one item. And me i have multiple or arrays

  $data=$request->all();
      $lastid=Addressitems::create($data)->id;
      if(count($request->product_name) > 0)
     {
        foreach($request->product_name as $Addressitems=>$v){
            $data2=array(
                'address_id'=>$lastid,
                'product_name'=>$request->product_name[$Addressitems],
                'quantity'=>$request->quantity[$Addressitems],
                'price'=>$request->price[$Addressitems],
                'amount'=>$request->amount[$Addressitems],
            );

            sales::insert($data2);
                //update stocks
            $product = Product::find(1);

                      $stock = Stock::where('pid', $product->id);
                      $stock->decrement('quantity', 1);



        }
    }
    return redirect('salesview')->with('success', 'Successfully Stored');
    
  }