lundi 19 octobre 2020

Export excel to specific path (Laravel5.8)

I already found the question that other asked .But, I didn't found any solution for file downloading to specific Path. Please Help me. This is the error that I'm facing
Error image

This is my Controller.blade.php

public function export() 
{
  
    $date=date('Ymd');
    $file='File_'.  $date.'_PCLists.xlsx';
    return Excel::store(new PcListsExport, $file,'real_public', \Maatwebsite\Excel\Excel::XLSX );
}

This is filesystem.php

  'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],
    'real_public' => [
        'driver' => 'local',
        'root' => 'D:/DownloadFile/',
        'url' => env('APP_URL'),
        'visibility' => 'public',
    ],

    's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => env('AWS_URL'),
    ],

],


via Chebli Mohamed

dimanche 18 octobre 2020

How to add chunk to a config file in laravel?

I have to add the data from the table to the API.

Say for ex, if I have 1000 records in my table how will I add the datas using chunks. From the config file I should use the chunk size.

My code looks something like this and I want to convert the array to a string so I used implode function.

public function addToList($data)
    {
        $numbers = [];

        foreach ($data as $item)
        {
            $numbers[] = $item->value . ',id:' . $item->id . ',email:' . $item->email . ',name:' . $item->name;
        }

        $numbers = implode('|', $numbers);
}

How will I add chunks to the above code ?

How to fetch the chunk information from the config file and to implement it in the code.

$data is the data from the table.

Could someone please help me? Thank you.



via Chebli Mohamed

Can't understand a logic of Object And Array in php

If i wrote this line on Laravel's routes/web.php

dd( app()['config']["auth.guards.web"] );

It outputs this:

array:2 [▼
  "driver" => "session"
  "provider" => "users"
]

Thats cool, but my question is since app()['config'] returns an object so how this ["auth.guards.web"]works? Even there is no index with that name!
Outside of laravel I tried to write a class named Test, so that it returns same output but i got an error! Which is,

Fatal error: Uncaught Error: Cannot use object of type Test as array 

Can anyone explain it with core php?



via Chebli Mohamed

Laravel NumberFormatter Output issue

I am trying to convert total into words and it gives me a wrong output.

I have to pass this in which is in laravel blade template into words

Here is my code

@php
    $num = $receipt_details->total;
    $f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
    echo $f->format($num);
@endphp 

The output I get is Zero for all the totals.



via Chebli Mohamed

QueryException SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value

QueryException SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'first' for column laravel.episodes.number at row 1 (SQL: insert into episodes (title, course_id, type, description, time, number, videoUrl, updated_at, created_at) values (Genetic Algorithm, 2, free,

this is Ga

, 1:25:00, first, one.mp4, 2020-10-18 17:50:09, 2020-10-18 17:50:09))

in Connection.php line 647

what can I do? Connection.php line 647 is:

""" 646       catch (Exception $e) {

647 throw new QueryException( 648 $query, $this->prepareBindings($bindings), $e 649 );"""



via Chebli Mohamed

Transfer the project from vuecli to Laravel Mix

I built the front-end section in vue-cli. Now I want to transfer it to Laravel to hit the back-end What is the best solution? My project is SPA and I have used many components



via Chebli Mohamed

How to get checkbox array from jquery form loop serialize data in laravel request?

I created a form using jquery loop:

function initForm(sl) {
       

        var newElement = '<tr class="trwrapper" id="tr' + sl + '">' +
                '<td>' + sl + '</td>' +
                '<td> <select  name="sub_head_id[]" title="Payable To Name"  class="select2_el form-control"><option value="0">- Search Sub Head -</option></select></td>' +
                '<td> <label class="radio-inline"><input type="radio"  id="r' + sl + '" value="r' + sl + '"  name="is_net_paid[]"   /> <nobr>Is Net Paid</nobr></label></td>' +
                '<td><input type="number" value=""  class="form-control" name="dr_amount[]" placeholder="0"/></td>' +
                '<td><input type="number" value=""  class="form-control" name="cr_amount[]" placeholder="0"/></td>' +
                '<td><a href="#" class="btn_remove btn-xs btn-danger btn" id="' + sl + '"> <i class="fa fa-remove"></i> Remove</a></td>' +
                '</tr>';
        $("#items-array").append($(newElement));
        initailizeSelect2();
    }

enter image description here

Save function(partial):

 var formData = $('#vForm').serialize();
            e.preventDefault();        

            $.ajax({
                url: "",
                method: "POST",
                data: {
                    "_token": "",
                    data: formData
                },

Laravel post method (partial) :

public function store(Request $req)
    {
        //try {

        /*
                $this->validate($req, [
                    'work_id' => 'required|unique:works|max:191',
                    'payable_id' => 'required',

                ]);*/


        parse_str($req->data, $data);


        \Log::info($data);

The Log prints this:

 'sub_head_id' => 
  array (
    0 => '0',
    1 => '0',
    2 => '0',
  ),
  'dr_amount' => 
  array (
    0 => '',
    1 => '',
    2 => '',
  ),
  'cr_amount' => 
  array (
    0 => '',
    1 => '',
    2 => '',
  ),
  'is_net_paid' => 
  array (
    0 => 'r3',
  ),

Problem:

The radio button value send only one array. Then how can i save data of which row is checked as "is_net_paid" ?

dr_amount , cr_amount,sub_head_id all send 3 array but radio button not.



via Chebli Mohamed