app/Http/Controllers/InvoicesController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $request->validate([
            'invoices_number' => 'required',
            'invoices_date' => 'required|date',
            'Due_date' => 'required|date',
            'section_id' => 'required',
            'products' => 'required',
            'amount_collection' => 'required',
            'amount_commission' => 'required',
            'discount' => 'required',
        ]);
        invoices::create([
            'invoices_number' => $request->invoices_number,
            'invoices_date' => $request->invoices_date,
            'due_date' => $request->Due_date,
            'product' => $request->products,
            'section_id' => $request->section_id,
            'Amount_collection' => $request->amount_collection,
            'Amount_commission' => $request->amount_commission,
            'discount' => $request->discount,
            'rate_vat' => $request->rate_vat,
            'value_vat' => $request-> value_vat,
            'total' => $request->total,
            'note' => $request->note,
            'user' => Auth::user()->id,
            'value_status' => '2',
            'status' => 'غير مدفوعة' ,
        ]);
        $invoice_id = invoices::latest()->first()->id;
        invoices_details::create([
            'Invoices_id' => $invoice_id,
            'invoices_number' => $request->invoices_number,
            'product' => $request->products,
            'section' => $request->section_id,
            'value_status' => '2',
            'status' => 'غير مدفوعة' ,
            'note' => $request->note,
            'user' => Auth::user()->name,
        ]);
        if ($request->hasFile('attachment')) {
            $invoice_id = invoices::latest()->first()->id;
            $image = $request->file('attachment');
            $file_name = $image->getClientOriginalName();
            $invoices_number = $request->invoices_number;
            $attachment = new invoices_attachments();
            $attachment->file_name = $file_name;
            $attachment->invoices_number = $invoices_number;
            $attachment->created_by = Auth::user()->name;
            $attachment->invoices_id = $invoice_id;
            $attachment->save();
            $image_name = $request->attachment->getClientOriginalName();
            $request->attachment->move(('Attachments/'.$invoices_number), $image_name);
        }
        session()->flash('Add','تم أضافة الفاتورة');
        return redirect('/invoices');
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'invoices_number' => 'required' , 'invoices_date' => 'required|date' , 'Due_date' => 'required|date' , 'section_id' => 'required' , 'products' => 'required' , 'amount_collection' => 'required' , 'amount_commission' => 'required' , 'discount' => 'required' , ] ) ; invoices :: create ( [ 'invoices_number' => $ request -> invoices_number , 'invoices_date' => $ request -> invoices_date , 'due_date' => $ request -> Due_date , 'product' => $ request -> products , 'section_id' => $ request -> section_id , 'Amount_collection' => $ request -> amount_collection , 'Amount_commission' => $ request -> amount_commission , 'discount' => $ request -> discount , 'rate_vat' => $ request -> rate_vat , 'value_vat' => $ request -> value_vat , 'total' => $ request -> total , 'note' => $ request -> note , 'user' => Auth :: user ( ) -> id , 'value_status' => '2' , 'status' => 'غير مدفوعة' , ] ) ; $ invoice_id = invoices :: latest ( ) -> first ( ) -> id ; invoices_details :: create ( [ 'Invoices_id' => $ invoice_id , 'invoices_number' => $ request -> invoices_number , 'product' => $ request -> products , 'section' => $ request -> section_id , 'value_status' => '2' , 'status' => 'غير مدفوعة' , 'note' => $ request -> note , 'user' => Auth :: user ( ) -> name , ] ) ; if ( $ request -> hasFile ( 'attachment' ) ) { $ invoice_id = invoices :: latest ( ) -> first ( ) -> id ; $ image = $ request -> file ( 'attachment' ) ; $ file_name = $ image -> getClientOriginalName ( ) ; $ invoices_number = $ request -> invoices_number ; $ attachment = new invoices_attachments ( ) ; $ attachment -> file_name = $ file_name ; $ attachment -> invoices_number = $ invoices_number ; $ attachment -> created_by = Auth :: user ( ) -> name ; $ attachment -> invoices_id = $ invoice_id ; $ attachment -> save ( ) ; $ image_name = $ request -> attachment -> getClientOriginalName ( ) ; $ request -> attachment -> move ( ( 'Attachments/' . $ invoices_number ) , $ image_name ) ; } session ( ) -> flash ( 'Add' , 'تم أضافة الفاتورة'); return redirect ( '/invoices' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// move file to the server // to send mail notification // $user = User::first(); // $user->notify(new AddInvoice($invoice_id)); // Notification::send($user , new AddInvoice($invoice_id));