0

Here is my code:

return PDF::loadFile($url)
    ->setPaper('a4')
    ->setOption('margin-top', 10)
    ->stream('somefile.pdf');

As I am calling this method on multiple locations, is there some kind of option to call it in a way like this?

return PDF::loadFile($url)
    ->callSettings()
    ->stream('somefile.pdf');

Where the settings are ->setPaper('a4')->setOption('margin-top', 10).

1
  • 3
    you have to make a method "callSettings" in the object returned by PDF::loadFile() (I guess it is a PDF...). If so, make a method in the class PDF returning this->setPaper('a4')->setOption('margin-top', 10) (you may have to use self:: instead of $this-> Commented Jul 17, 2015 at 9:41

1 Answer 1

1

It's easy. Just implement a new callSettings() method in PDF class, that calls those methods and returns $this:

public function callSettings()
{
    $this->setPaper('a4')
         ->setOption('margin-top', 10);

    return $this;
}
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.