1

I have a view.blade.php that calls a wrapper.php that return some value for an iframe in the view.

I'm able to return that value, but I have to do some work with other methods in my laravel classes.

It's possible to instatiate the classes inside the wrapper php and call methods, or call static class methods?

Project structure:

- project
-- app
--- Http
---- Classes
----- RepositoryUtil.php
...
-- public
--- Wrapper.php
...
-- resources
--- views
---- partials
----- view.blade.php

Code inside view.blade.php:

<iframe id="reader" src="/libs/pdfjs/web/viewer.html?file=http://project.dev/Wrapper.php?id={{$encrypted}}">
</iframe>

Code inside Wrapper.php:

<?php
// tried: use App\Http\Classes\RepositoryUtil
// tried: \App\Http\Classes\RepositoryUtil::getValue();
// tried: {{RepositoryUtil::getValue()}}
$myValue = RepositoryUtil::getValue(); #not work

var_dump($myValue);
?>

Code inside RepositoryUtil.php

<?php

class RepositoryUtil{
    public static function getValue(){
        dd("getValue!");
        return "value";
    }
}

?>

The error:

( ! ) Fatal error: Class 'RepositoryUtil' not found in /home/vagrant/Code/project/public/Wrapper.php on line 14

EDIT: I can call static class method adding include_once("../App/Http/Classes/RepositoryUtil.php"); at the top of Wrapper.php but when I call the "laravel methods" like $decrypted = Crypt::decrypt($encrypted); it return the error:

( ! ) Fatal error: Class 'Crypt' not found in /home/vagrant/Code/project/App/Http/Classes/RepositoryUtil.php on line 13

Error

Thanks

1 Answer 1

1

After many and many attemps and research, I figure that out!

Post my Wrapper.php code:

<?php

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$value = RepositoryUtil::getValue();

// Your other staff here... 

?>

The problem was that after calling external php, Laravel wasn't booted!

I tried to boot with require __DIR__.'/../bootstrap/autoload.php';, $app = require_once __DIR__.'/../bootstrap/app.php'; and calling $app->boot(), and it worked.

But there were other problems: Facades were not loaded, but I can see into "alias" array when log $app variable. You have to boot kernel to get Facades back.

Using Laravel 5.1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.