I have upgraded my app from Laravel 4.2 to 5.5 and I am getting issues with the queue.
public function saved(Model $review)
{
if (App::runningInConsole()) {
return;
}
$data = [
'review' => serialize($review),
'action' => self::ACTION_SAVE
];
Queue::push(new UpdateReviewSummaryQueue, $data);
}
When I run this on model save, I am getting an error that the UpdateReviewSummaryQueue class does not exist. I've ran composer dump-autoload and namespacing seems to be fine. Are there any other issues I might look into?
I've also added
use SerializesModels;
as Laravel upgrade guide suggested
In laravel 5.5 you now dispatch jobs rather than push. See https://laravel.com/docs/5.5/queues#dispatching-jobs for full documentation.
Try :
dispatch((new UpdateReviewSummaryQueue($data));
The issue was actually in this line:
Queue::push(new UpdateReviewSummaryQueue, $data);
Changing it to this made it work:
Queue::push(UpdateReviewSummaryQueue::class, $data);
Related
I am using Maatwebsite/Excel in my application and when i get the error
Call to undefined method Maatwebsite\Excel\Excel::create()
from one of my controllers. I am using laravel 5.6 and i have followed the documentation strictly and other very few related discussions online to solve this, but i still get the error.
How do i solve this error please
app.php
'provider' => 'Maatwebsite\Excel\ExcelServiceProvider',
'alias' => 'Excel'=> 'Maatwebsite\Excel\Facades\Excel',
Controller
$cl = ClassModel::Select('name')->where('code',$input->class)->first();
$input->class=$cl->name;
$fileName=$input->class.'-'.$input->section.'-'.$input->session.'-'.$input->exam;
// return $students;
Excel::create($fileName, function($excel) use($input,$subjects,$students) {
$excel->sheet('New sheet', function($sheet) use ($input,$subjects,$students) {
$sheet->loadView('app.excel',compact('subjects','input','students'));
});
})->download('xlsx');
You are using 2.* syntax while using 3.* package. Please refer to the correct documentation over here: https://laravel-excel.maatwebsite.nl/docs/3.0/export/basics
Try to decrease the version using :
composer require "maatwebsite/excel=2.1.0"
There have been many changes in the new version of the package.
In your composer.json file inside the require array replace your package with this:
"maatwebsite/excel": "~2.1.0",
and then run composer update
This should work fine.
Please switch to version 2*
Version 3.0 of that package doesn't handle imports yet. Release date for this feature is unknown. See this post for more details: maatwebsite
I have worked it around but I know it's not a perfect solution. It will really help you if you only have concerns with the uploading not adjusting Crudbooster features.
I removed the extra features from the importing screen of the Crudbooster by applying the following CSS in the crudbooster-controller.
$this->style_css = "ul.nav li:not(:first-child) {
display: none;
}";
I copied the getImportData() method from Crudbooster CBController and overridden it in the crudbooster-controller by the following code.
//PHP
//By the way, you can still create your own method in here... :)
public function getImportData()
{
$this->cbLoader();
$data['page_menu'] = Route::getCurrentRoute()->getActionName();
$data['page_title'] = 'Import Data';
if (request('file') && ! request('import')) {
$file = base64_decode(request('file'));
$file = storage_path('app/'.$file);
$data = Excel::import(new ProductImport, $file);
CRUDBooster::redirect('/admin/products', cbLang("alert_add_data_success"), 'success');
}
return view('crudbooster::import', $data);
}
Importing is working fine now
I have two function in my controller and service. I want to call a function in service. Here is my code :
Controller:
public function findNeighborhoodGet(): array
{
$regionCenter = Request::get('region_center');
$distanceService = \App::make('App\web\one\Infrastructure\Service\Google\Map');
try {
$userPoint = $distanceService->getOriginPoint($regionCenter);
}
.
.
.
return $result
}
my service (Map.php) :
public function getOriginPoint(string $origin):Point
{
dd($origin);
return $this->getPointObject($origin);
}
Actually , I get an error :
A non well formed numeric value encountered
at this line:
public function getOriginPoint(string $origin):Point
How to solve it?
This is a bug in the symfony/var-dumper package when using PHP7.1. It was fixed in version 2.7.16, 2.8.9, 3.0.9 and 3.1.3. See the pull request: https://github.com/symfony/symfony/pull/19379
In my case, I needed to composer update my laravel framework packages, as my vendor directory copy of that package was at 2.7.9. (I'm using Laravel 5.1; later versions use 2.8 and 3.0 of symfony, which also had the bug)
I had the same issue on Laravel 5.2 PHP 7.1. If you don't want to update the entire framework, you can do:
composer update symfony/var-dumper
as stated here.
I've tried to using queue for everytime user register and send an email to them to verify.
I'm doing it successfully using Laravel 5.1
I just wandering how can I can stop current queue if I got an error and then when I fix it I restart the job from the last queue?.
How about the error like this:
[InvalidArgumentException]
View [emails.versify_email] not found.
[InvalidArgumentException]
View [emails.versify_email] not found.
[InvalidArgumentException]
View [emails.versify_email] not found.
I've tried at homestead using:
public function failed(){
//I've tried send email but it not sending
}
or at AppServiceProvider
Queue::failing(function ($connection, $job, $data) {
$user ='mymail#gmail.com';
Mail::send('emails.fail_queue', ['user' => $user], function ($m) use ($user) {
$m->subject('Failing:' . $user)
->to($user);
});
});
None of the them is working.
what should i do if its like that when happened at production?.
When an exception is thrown from the handler Laravel tries to release the job back to the queue unless it is explicitly deleted.
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Queue/Worker.php#L198-L227
You can use the $delay parameter to put back in the queue with delay. Or better just bury the job yourself, if you are able to detect the issue.
$this->job->bury()
Slightly odd one here.
I have Persons and Actions. Persons can have many Actions, while each Action belongs to only one Person. I'm using Chumper's Datatables to display a list of people, including a count of their actions.
Since migrating to a production (forge) server, I'm getting
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR)
Class 'action' not found
when calling the datatable. The error shown
/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:721
public function hasOne($related, $foreignKey = null, $localKey = null)
{
$foreignKey = $foreignKey ?: $this->getForeignKey();
$instance = new $related;
$localKey = $localKey ?: $this->getKeyName();
suggests it's a problem with my hasMany relationship:
# /models/Person.php
class Person extends Eloquent {
public function actions()
{
return $this->hasMany('Action');
}
# /models/Action.php
class Action extends Eloquent {
public function person()
{
return $this->belongsTo('Person', 'person_id');
}
I assume these are fine, however, as it all works locally. Datatables also works fine elsewhere, calling through other items and their related actions with no trouble.
I've tried composer dump-autoload and artisan dump-autoload on the production server, to no avail. The deployment script on forge is below:
git pull origin master
composer install
php artisan migrate --env=production
I can't tell if it's a config issue, a database issue, a code issue or something else entirely. I've been back through the many similar questions but nothing's jumped out. Any help much appreciated.
for who may have the same problem, triple check the casing of your model! I had it wrong, that's why locally on mac was working but not on the server
So I think I'd borked this one myself.
I'd been lazy and left function datatablePersons() in PersonsController.php using an old 'count' method, relying on long-defunct relationships (that caused n+1, so had to be binned), hence it wobbling over an actions class whenever that relationship was called upon.
Datatable functions in other controllers (with a cleaner 'count' method) work fine, so I've just rewritten datatablePersons() to use the same method.
I've not quite got the query right (in eloquent, at least) yet - see this question here: mysql join ON and AND to laravel eloquent - but the class not found error has certainly gone away.
I'm (massively) guessing that the classmap on the local machine hadn't been flushed since whatever was removed was removed, while the production machine is rebuilt every push, hence the disparity...?
Either way, it's no longer an issue.
I have upgraded Laravel from 4.0 to 4.1 recently in a few instances. Today I did the upgrade in yet another instance and found out that there is something wrong with the User model. The models/User.php file is still there, but I don't think it is used by Laravel anymore. My question is: why?
To demonstrate the issue, I have created the following entries in my routes.php:
Route::get('test1', function()
{
$course = Course::find(4);
return ($course->users()->first());
});
Route::get('test2', function()
{
$user = User::find(22);
return ($user->courses()->first());
});
Both these entries are correct regarding syntax and the database object (course with id 4 exists and user with id 22 exists). My Course.php model has the following:
public function users()
{
return $this->belongsToMany('User')->withPivot('participant_role')->withTimestamps();
}
And my User.php has a corresponding entry:
public function courses()
{
return $this->belongsToMany('Course')->withPivot('participant_role')->withTimestamps();
}
Now if I launch the first URL, /test1, I get a working JSON entry as a result. As expected.
With the second URL, /test2 however I get an error message:
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::courses()
open: /home/simoa/laravelapps/clientname/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php `
I think there is something wrong here. Why is my Laravel instance trying to call the courses() method from the Illuminate\Database\Query\Builder class? That isn't normal, right?
As I said earlier, everything else works perfectly, except things to do with the User model.
The issue was caused by an invalid entry in the file vendor/composer/autoload_classmap.php.
For some reason during the 4.1 upgrade (probably running the command: composer update) the entry for 'User' => $baseDir . '/app/models/User.php' has turned into 'User' => $baseDir . '/app/models/old_User.php' in that file.
I did have an old backup/dev file called old_User.phpin my models directory and for some reason, it seems, composer has mapped User class to that file.
Solution: delete old_User.php and re-run composer update.
try running php artisan clear-compiled and then php artisan optimize