Error Missing argument 1 for App Http Controllers ImageController App Http Controllers closure called in C xampp htdocs imagesharing vendor laravel framework src Illuminate Cache Repository php

0 votes

I have

public function thumb($hash, $extension)
{
    Cache::remember('thumb-'.$hash, 15, function() {
        $image = Image::where('hash', $hash)->first();
    });

If I run that I get ErrorException in ImageController.php line 69: Undefined variable: hash. I tried to pass $hash to function like so:

Cache::remember('thumb-'.$hash, 15, function($hash)

but then got another error as below:

Missing argument 1 for App\Http\Controllers\ImageController::App\Http\Controllers{closure}(), called in C:\xampp\htdocs\imagesharing\vendor\laravel\framework\src\Illuminate\Cache\Repository.php on line 316 and defined

How do I pass argument so I can use it in my query?

Nov 2, 2020 in Laravel by kartik
• 37,510 points
2,071 views

1 answer to this question.

0 votes

Hii,

You need to pass it using use.

Cache::remember('thumb-'.$hash, 15, function() use ($hash) {
    $image = Image::where('hash', $hash)->first();
});

Hope it works!!

answered Nov 2, 2020 by anonymous
• 82,880 points

Related Questions In Laravel

0 votes
1 answer

How to set port for php artisan.php serve in Laravel?

Hii @kartik, When we use the php artisan serve ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,880 points
16,197 views
0 votes
2 answers

Error:Class 'App\Http\Controllers\App\Model' not found?

Class ‘App\Http\Controllers\Auth’ Not Found in Class ‘App\Http\Controllers\Auth’ not ...READ MORE

answered Aug 6, 2020 in Laravel by pakainfo
17,069 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
21,905 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,690 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,560 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,882 views
0 votes
1 answer

Error: Class 'TestCase' not found in D:\xampp\htdocs\laravel\app\tests\ExampleTest.php on line 3 ,

Hello @kartik, Run following command in your project's ...READ MORE

answered Sep 28, 2020 in Laravel by Niroj
• 82,880 points
1,971 views
0 votes
1 answer

Error:Missing argument 2 for App\Http\Controllers\EventsController::remindHelper()

Hello @kartik, When you define this route: Route::get('events/{id}/remind', [ 'as' ...READ MORE

answered Nov 12, 2020 in Laravel by Niroj
• 82,880 points
481 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP