BadMethodCallException Method [getReport] does not exist - php

BadMethodCallException Method [getReport] does not exist.
But there is a method called getReport().
other reports are working but first one is not working. i wrote exactly the same codes.
There is a controller, but my laravel couldn't find it.
i tried:
php artisan route:clear
php artisan cache:clear
but it didn't work.
web.php->
Route::get('/report/{id}', 'ReportController#getReport');
Route::get('/report2/{id}', 'ReportController#getReport2');
ReportController.php ->
public function getReport(Request $request,$id)
{ $users=Users::find($id);
$pdf = PDF::loadView('admin.report', compact('users'));
return $pdf->stream(); }
codes are working on my pc (Localhost) But they are not working on Host (Website)

do it this way
public function getReport($id)
{
$users=Users::find($id);
$pdf = PDF::loadView('admin.report', compact('users'));
return $pdf->stream();
}

Laravel Controller doesn't exist, even though it clearly exists
it solved my problem...
Create a new file in app/controllers named TemplateController.php
Open up terminal and run composer dumpautoload -> This line solved my problem.
Thank You all

Related

cant download files in laravel in production

i am trying to download a file in laravel. It works fine in localhost but not in production. The file path is ok. but the problem is when i am trying to download it. It gives an error saying the file doesnt exist. Below is my code. please help. thanks in advance
public function getGo(Request $request){
$file=asset('storage/source/hey.png');
return response()->file($file);
}
Can you try the below code?. I think below code would be helpful.
public function getGo(Request $request){
$file=storage_path('source/hey.png');
return response()->file($file);
}

Laravel 5.5. queue push

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);

This Laravel route is returning different responses every time - where do I look for error?

This laravel route is returning the image sometimes and is returning an error page the other times. What could go wrong.
This route just returns the image like this:
public function image(Request $request) {
return response()->file(storage_path('app/'.$request->input('path')));
}
I'm storing images using this code:
$path = $request->p->store('public/images');
Storage::setVisibility($path, 'public');
I don't know what's going wrong. I see this log when the route is requested.
NOTICE: PHP message: [2017-09-25 18:33:25] production.ERROR:
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException:
The file
"/app/storage/app/public/images/YxNllK0iVKAxxUSCEhFHLo5sGZiXg5NNbGDbOVSL.jpeg"
does not exist in /app/vendor/symfony/http-foundation/File/File.php:37
Here's the route in it's full glory:
https://resonant-tower-177816.appspot.com/showimage?path=public/images/YxNllK0iVKAxxUSCEhFHLo5sGZiXg5NNbGDbOVSL.jpeg
This is definitely not because there's no image there. I can assure you the route works some of the times.
What could have gone wrong?
I'm using Laravel 5.4 on Google App Engine.
Wrong path "/app/storage/app/public/images"
The correct path is like "/storage/app/public/images"
So you should change
public function image(Request $request) {
return response()->file(storage_path('app/'.$request->input('path')));
}
to
public function image(Request $request) {
return response()->file(storage_path($request->input('path')));
}

Laravel - returning SSH output

Thanks for interest to this topic. I'm pretty new in Laravel and i have a little question. Maybe it's easy!
I have an SSH module in my Laravel that works this way:
The user fills the textarea element with Linux commands.
The command is passed with Ajax to a method called getExecute() located in the 'controllers' folder
I would like that this method returns me the full response of my SSH server, but this isn't happening. The only thing that the method returns is a blank space.
For example: I pass the command 'ls -la', and my response is all folders that the Linux find, like on terminal.
Can someone help me please?
Here is my code:
public function getExecute()
{
if(\Request::ajax()):
$ssh_command = \Input::get('ssh_command');
$ssh_response = null;
\SSH::run($ssh_command, function($line)
{
return $line.PHP_EOL;
});
endif;
}
OBS: The Ajax connection was tested and it's ok!
Thank you!
Finally solved! Solution below:
First i've created a variable called $output in my class.
private $output;
Then i modified my method to this:
public function postExecute()
{
$ssh_command = \Input::get('ssh_command');
$ssh_response = \SSH::run($ssh_command, function($line)
{
$this->output = $line.PHP_EOL;
});
return $this->output;
}
My method is not more Ajax, but i hope that all that i have to do is rollback to my ajax method like before.Thanks for all!

"User" model broken after Laravel 4.1 upgrade

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

Categories