在重用其他项目的代码时调用 Laravel 中的未定义函数
Called to undefined function in Laravel while reusing code from other project
我有这个 blade.php 应该会生成一个菜单:
<ul class="header-nav">
@foreach(config('menu.horizontal') as $menu)
<li class="{{set_active($menu['active'],'active')}} @if(isset($menu['children'])) has-child @endif">
<a href="{{$menu['link']}}" @if(isset($menu['children'])) data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" @endif><i class="{{$menu['icon']}}"></i> {{$menu['title']}}</a>
@if(isset($menu['children']))
<div class="dropdown-menu">
@foreach($menu['children'] as $child)
<a class="dropdown-item" href="{{$child['link']}}">{{$child['title']}}</a>
@endforeach
</div>
@endif
</li>
@endforeach
</ul>
使用这个数组:
return[
'horizontal' => [
[
'title' => 'Dashboard',
'link' => '/admin',
'active' => 'admin',
'icon' => 'fa fa-dashboard',
],
[
'title' => 'Settings',
'link' => '/admin/settings',
'active' => 'admin/settings*',
'icon' => 'fa fa-cogs',
],
[
'title' => 'Users',
'link' => '#',
'active' => 'admin/users*',
'icon' => 'fa fa-user',
'children' => [
[
'title' => 'All Users',
'link' => '/admin/users',
'active' => 'admin/users',
],
[
'title' => 'User Profile',
'link' => '/admin/users/1',
'active' => 'admin/users/*',
]
]
],
]
];
但是我得到这个错误:
ErrorException in 23bb0e870ad0fbd7e21a6ce757b7bc9560d31591.php line 3:
Call to undefined function set_active() (View: C:\xampp\htdocs\myproject\resources\views\admin\layouts\partials\nav\menu-horizontal.blade.php)
我从中复制它的应用程序中没有出现此错误。我检查了 set_active() 是否存在,它确实存在:
<?php
use App\Space\Settings\Setting;
function set_active($path, $active = 'active') {
return call_user_func_array('Request::is', (array)$path) ? $active : '';
}...
它也正是它在我的旧项目中的位置。为什么它在这里不起作用?
清除 view
、cache
并生成新密钥并重新运行 您的程序。
并提供755
或777
到存储文件夹
命令是
php artisan view:clear
php artisan cache:clear
php artisan key:generate
还有运行
composer update
我有这个 blade.php 应该会生成一个菜单:
<ul class="header-nav">
@foreach(config('menu.horizontal') as $menu)
<li class="{{set_active($menu['active'],'active')}} @if(isset($menu['children'])) has-child @endif">
<a href="{{$menu['link']}}" @if(isset($menu['children'])) data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" @endif><i class="{{$menu['icon']}}"></i> {{$menu['title']}}</a>
@if(isset($menu['children']))
<div class="dropdown-menu">
@foreach($menu['children'] as $child)
<a class="dropdown-item" href="{{$child['link']}}">{{$child['title']}}</a>
@endforeach
</div>
@endif
</li>
@endforeach
</ul>
使用这个数组:
return[
'horizontal' => [
[
'title' => 'Dashboard',
'link' => '/admin',
'active' => 'admin',
'icon' => 'fa fa-dashboard',
],
[
'title' => 'Settings',
'link' => '/admin/settings',
'active' => 'admin/settings*',
'icon' => 'fa fa-cogs',
],
[
'title' => 'Users',
'link' => '#',
'active' => 'admin/users*',
'icon' => 'fa fa-user',
'children' => [
[
'title' => 'All Users',
'link' => '/admin/users',
'active' => 'admin/users',
],
[
'title' => 'User Profile',
'link' => '/admin/users/1',
'active' => 'admin/users/*',
]
]
],
]
];
但是我得到这个错误:
ErrorException in 23bb0e870ad0fbd7e21a6ce757b7bc9560d31591.php line 3:
Call to undefined function set_active() (View: C:\xampp\htdocs\myproject\resources\views\admin\layouts\partials\nav\menu-horizontal.blade.php)
我从中复制它的应用程序中没有出现此错误。我检查了 set_active() 是否存在,它确实存在:
<?php
use App\Space\Settings\Setting;
function set_active($path, $active = 'active') {
return call_user_func_array('Request::is', (array)$path) ? $active : '';
}...
它也正是它在我的旧项目中的位置。为什么它在这里不起作用?
清除 view
、cache
并生成新密钥并重新运行 您的程序。
并提供755
或777
到存储文件夹
命令是
php artisan view:clear
php artisan cache:clear
php artisan key:generate
还有运行
composer update