0

I want to call a function that is in a controller for my form, how do I do it?

Function in FileUploadController

public function hasAnexos(){
        $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $id = explode("/", $url)[5];
        $diretorio = getcwd() . "/app/views/users/tickets/anexos/" . $id;

        if (!is_dir($diretorio)) {
            return false;
        } else {
            return true;
        }
    }

I want to call it in a .blade file

@if(hasAnexos())
    <form method="POST" action="download/{{ $ticket->id }}">
         <button type="submit" style="margin-top: 3%;" class="btn btn-success"><i class="fa fa-download"></i> Baixar anexos</button>
    </form>
@else
    <h4>Teste</h4>
@endif
  • 1
    hey maybe this helps ? : https://stackoverflow.com/questions/44021662/how-to-create-global-function-that-can-be-accessed-from-any-controller-and-blade – Met Br Mar 11 '21 at 18:22
  • If `hasAnexos()` doesn't do anything related to class functionality, you should rather put these in helper files. – nice_dev Mar 11 '21 at 18:22

0 Answers0