Laravel import php class to blade view

Viewed 1092

I want to include an own written ‍‍.‍php file in my blade view, so I can run the method inside the class.

It should be usable as var. for me somehow or printed in my view.

I need this later on in order to implement php functions and methods inside my webapplication (writing a tool that loads up a .csv file from the storage path that contains information I wanna extract & save in my database).

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);
    }
}

resources/views/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');
});
1 Answers
Related