php - Laravel 将 php 类导入刀片视图
问题描述
我想在我的刀片视图中包含一个自己编写的 <code>.php 文件,这样我就可以在类中运行该方法。
它应该可以用作 var。以某种方式对我来说或印在我看来。
稍后我需要它以便在我的 web 应用程序中实现 php 函数和方法(编写一个从存储路径加载 .csv 文件的工具,该文件包含我想要提取并保存在我的数据库中的信息)。
App\CustomClass\downloadLog.php
namespace App\CustomClass;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Facades\Hash;
use App\User;
class downloadLog
{
public static function save_log()
{
$string = "this is just a string";
print($string);
}
}
资源/视图/log.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head></head>
<body>
<div>I wanna see for instance my printed string here</div>
</body>
</html>
路线/web.php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::get('/log', function() {
return view ('log');
});
Route::get('/dashboard', function() {
return view ('menu');
});
Route::get('/search', function() {
return view ('searchbar');
});
Route::get('/games', function() {
return view ('searchbar');
});
Route::get('/data', function() {
return view ('searchbar');
});
解决方案
请尝试@php downloadLog::save_log('string') @endphp
您的刀片文件
有关更多信息,请参阅https://laravel.com/docs/7.x/blade#php
这个答案如何使用刀片模板中的类?
推荐阅读
- javascript - javascript - for 循环 - 仅每隔一个事件侦听器工作
- java - Java Criteria API - 如何使用 MySQL 的 ANY_VALUE
- c# - 以用户身份使用 selenium 打开 Chrome
- nginx - 扩展 realurl - 在 URL 中显示 SQL 查询部分
- java - Kotlin函数返回类型中的`out Interface`
- java - 为什么Java接口常量被Checkstyle中的ConstantName检查视为非公共的
- javascript - 带有 jQuery json 数据的动态菜单
- javascript - 如何在浏览器通知 Web API 中添加自定义按钮?
- version-control - 将 bcompare 与 clearcase 一起使用
- javascript - 如何在 HTML 字符串中放置 for 循环