Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'Batch' not found #7

Closed
Cholowao opened this issue Apr 23, 2018 · 9 comments
Closed

Class 'Batch' not found #7

Cholowao opened this issue Apr 23, 2018 · 9 comments

Comments

@Cholowao
Copy link

I have added to aliases and providers in app.php but it does not seem to work.

My code:

public function storeBanks($request) {
	$selected = $this->getListOfSelectedBanksIds();
	return Batch::update('bank_school', $this->createUpdateBankObject($request, $selected));
}

@mavinoo
Copy link
Owner

mavinoo commented Apr 23, 2018

Hi

What is the output of this function?
$this->createUpdateBankObject($request, $selected)

Like this do

$array = [
 [
  'id' => 1,
  'name' => 'mohammad'
 ],
 [
  'id' => 10,
  'name' => 'Cholowao'
 ],
 [
  'id' => 20,
  'username' => 'cholowao'
 ]
];
Batch::update(   'NameTable'  ,  $array  ,     'id'  );

Please https://github.com/mavinoo/laravelBatch/blob/master/README.md

@Cholowao
Copy link
Author

	private function createUpdateBankObject($request, $selected) {

		$update = [];
		foreach ($request->all() as $key => $request) {
            if (!in_array($request['id'], $selected)) {
                continue;
            }
			$arr = array(
                'bank_id' => $request['id'],
				'account_no' => $request['account_no'],
			);
			$update[] = $arr;
		}
		return $update;
	}

with output

[
	{
		"bank_id": 1,
		"account_no": "34534758"
	}
]

@Cholowao
Copy link
Author

I tried your example and use Batch; and the top. But still "message": "Class 'Batch' not found", did I missed installation steps.

@mavinoo
Copy link
Owner

mavinoo commented Apr 23, 2018

example :

private function createUpdateBankObject($request, $selected)
{
    $update = [];
    
    foreach ($request->all() as $key => $request)
    {
        if (!in_array($request['id'], $selected))
        {
            continue;
        }
        
        $arr = array(
            'bank_id'       => $request['id'],
            'account_no'    => $request['account_no'],
        );
        
        $update[] = $arr;
    }
    
    return $update;
}

$requests = [
    [
        'id' => 10,
        'account_no' => 'ok'
    ],
    [
        'id' => 1,
        'account_no' => '34534758'
    ],
    [
        'id' => 20,
        'account_no' => 'ok'
    ],
];

$selected = [1];



echo '<pre/>';
print_r(createUpdateBankObject($requests, $selected));

output :

Array
(
    [0] => Array
        (
            [bank_id] => 1
            [account_no] => 34534758
        )

)

in Batch:

Batch::update('bank_school' ,  createUpdateBankObject($requests, $selected))  ,  'bank_id');

@mavinoo
Copy link
Owner

mavinoo commented Apr 23, 2018

for use ::

use Mavinoo\LaravelBatch\LaravelBatchFacade as Batch;

@Cholowao
Copy link
Author

I am using it in the controller. Here is my 'header'

<?php

namespace App\Http\Controllers\Banks;
use App\BankSchool;
use App\Http\Controllers\Controller;
use App\Http\Controllers\HelperController as Helper;
 use Mavinoo\LaravelBatch\LaravelBatchFacade as Batch;
use Illuminate\Http\Request;
...

but strangely, it changed to Class Batch does not exist

@mavinoo
Copy link
Owner

mavinoo commented Apr 23, 2018

please change to

use Mavinoo\LaravelBatch as Batch;

!!

@Cholowao
Copy link
Author

It says Class 'Mavinoo\LaravelBatch' not found

@Cholowao
Copy link
Author

For some reason I failed to do importing but instead I created a class in my App\Controller\Banks and pasted codes from your src and it worked like a charm!

Thanks for the source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants