my closure not returning

Posted 1 month ago by afghany

this my web.php file

Route::get('/', function () {

    $message = "it's working";

    $ResponseHandler = new ResponseHandler();

    $view = function () use ($message) {

        return view('welcome');
    };

    $json = function () use ($message) {

        $c = new ApiController();

        return $c->fetched(compact('message'));

    };

    $ResponseHandler->response($view, $json);
});

and here is my ResponseHandler class

<?php

namespace App\Utilities;

use Closure;

class ResponseHandler
{

    public function response(Closure $html , Closure $json)
    {
        return request()->header('accept') ==  "application/json" ? $this->json($json) : $this->html($html) ;
    }

    public function json(Closure $closure)
    {

        return $closure();

    }

    public function html(Closure $closure)
    {
        return $closure();

    }

}

when i send the request with header accept application/json or just a normal http request from the browser i am not getting any result .

Please sign in or create an account to participate in this conversation.