【问题标题】:Laravel import php class to blade viewLaravel 将 php 类导入刀片视图
【发布时间】:2020-09-02 08:31:19
【问题描述】:

我想在我的刀片视图中包含一个自己编写的 ‍‍.‍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>

routes/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 database laravel class


    【解决方案1】:

    请在您的刀片文件上尝试@php downloadLog::save_log('string') @endphp

    更多信息请查看https://laravel.com/docs/7.x/blade#php

    这个答案How to use class from blade template?

    【讨论】:

      猜你喜欢
      • 2022-01-05
      • 2013-08-03
      • 1970-01-01
      • 2019-04-23
      • 2017-08-07
      • 1970-01-01
      • 2016-09-09
      • 2018-03-23
      • 1970-01-01
      相关资源
      最近更新 更多