PHP包含。 我无法弄清楚为什么我无法运行我的功能

Ok so I have been reading the PHP Docs trying to figure out what isn't working here. So I'm using Laravel and in my master file in my header I am including my functions file located in public/includes. I have used a simple php code instead of blade functions for this.

public.blade.php

<?php include 'includes/nashFunctions.php'; ?>

I am positive I'm extending the master file where I am trying to call my data. I've got a function in there, but I wanted to test it with a simple variable by putting

<?php $hello = 'hello world'; ?>

in the nashFunctions.php. Now when I go into my file and try and call the variable:

<?php echo $hello; ?>

I get this error message:

Undefined variable: hello (View:/resources/views/teams.blade.php)

What am I doing wrong here?

So I found help elsewhere, but I wanted to put my answer in case anyone else came across it. Here is the help I was given by /u/11ry on reddit:

Instead of doing it the way you've described, create a file in the app folder and call it helpers.php or functions.php or whatever. Then, goto your composer.json file and add this . Don't forget to run a "composer update" when done.

enter image description here

Your nashFunctions.php located in public\includes folder and your teams.blade.php is located in view folder. If you want to use Raw PHP Code you have to write the full path of the file location.

Change <?php include 'includes/nashFunctions.php'; ?> to <?php include '../../public/includes/nashFunctions.php' ?>

Hope it will work.