Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dane5890's avatar

How To Include External PHP File That Is Not a Blade View Page

Hi, I'm new to Laravel. My project is based on version 5.4, but when I try to include an external php file that's not a blade view file, nothing works. The traditional <php include method is not accepted.

I've tried methods such as <?php include public_path() . and even app_path(), and those don't work. I'm confused. What am I doing wrong?

Dane

0 likes
7 replies
dane5890's avatar

Thanks, do I define ROOTUP and for that matter my custom function in the app controller file? Where exactly. I'm completely new at this.

jlrdw's avatar

ROOTUP is something in my application, not yours. It was an example of resolving a path.

Just point to the correct location of the file you want to include. I don't know of any other way to explain. Did you go to http://php.net/manual/en/function.include.php and read the php manual on this subject.

dane5890's avatar

I'm aware that Rootup is your project variable. My question is, where did you define the Rootup variable in your project? Was it on the blade.page itself or in the app folder with controller. That's my question.

Thanks again for your help, and yes I looked at the manual, but that manual mostly references classic php includes which are useless in Laravel %.4

jlrdw's avatar

Index.php, it is a constant in my project

dane5890's avatar

I figured it out. Thanks again for the help!

mackecm2's avatar

Hi, I'm also new to Laravel, using 5.4, and I can't get the @include to work either. dane5890 says that he has "figured it out", but he doesn't say what the solution is!!!!

I have a view in the resources/views directory, and I just want to include some simple html divs which I would like to be in a separate .inc file.

Most of the forums (fora?) that I have found are talking about Laravel 4, so is there anyone that can point me at some clear instructions on how to do it in 5.4?

Basically, I have an index.blade.php view in the resources/views/xxx directory, which works fine, but has divs of html which I'd like to get out of the way in a notes.inc.blade.php file, and then @include it into the index.

I've tried creating the .inc file in the same folder, then using @include('notes.inc') , but this doesn't work. I've also tried moving the inc file to the resources/views directory and then using @include('xxx.notes.inc') but again no joy.

I haven't changed any path definitions or configs.

Please or to participate in this conversation.