1

I have a file full of logs! I called them apache.logs.
So now I need to get them in Laravel and I don't know how.
I just want to save all logs in a variable ($logs) and view them.

public function getlogs ()
    {
        $logs = \Request::file('apache.log');
        return view('logs' , [
            'all_logs' => $logs
        ]);
    } 

This doesn't work and I don't know what I need to change.

3
  • Can I ask which Laravel version, you're using? Commented Oct 19, 2015 at 6:32
  • where is the apache.log in laravel? Commented Oct 19, 2015 at 6:36
  • in my project folder - just like the composer.json Commented Oct 19, 2015 at 6:38

1 Answer 1

2

If your using \Request::file then the file should come along with the request params, But here seems like you want to access a stored file in file system using laravel

to do that

ini_set('memory_limit','256M');
$logs = \File::get('apache.log');
return view('logs' , [
    'all_logs' => $logs
]);

UPDATE

if you file is in root same like composer.json then you need to change the path to match with it like

ini_set('memory_limit','256M');
$path = base_path()."/apache.log"; //get the apache.log file in root
$logs = \File::get($path);

return view('logs' , [
    'all_logs' => $logs
]);

wrap this in a try catch block for best practice, because in some case if apache.log not exists or not accessible laravel trow a exception, we need to handle it

try {

    ini_set('memory_limit','256M');
    $path = base_path()."/apache.log"; //get the apache.log file in root
    $logs = \File::get($path);

    return view('logs' , [
        'all_logs' => $logs
    ]);

} catch (Illuminate\Filesystem\FileNotFoundException $exception) {
    // handle the exception
} 
Sign up to request clarification or add additional context in comments.

3 Comments

thanks this works-- now i have a other porblem haha but i dont think anyone could help me there xD
Allowed memory size of 134217728 bytes exhausted (tried to allocate 176646626 bytes) - haha :D
lol yeah seems like a large file put this and check ini_set('memory_limit','256M');, made a update please check :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.