manifestor
manifestor

Reputation: 1452

Create a file on the filesystem using placeholders with PHP / Laravel 5.5

I'm writing a GUI where each user should get the possibility to create a certain file on the filesystem. As the file is individual for each user I need to edit it before creating it. The fact that I just need to change very few things for each user and everything else in the file stays the same, makes me wonder: Is it somehow possible to create a file on the filesystem using blade placeholders?

Upvotes: 0

Views: 38

Answers (1)

Iarwa1n
Iarwa1n

Reputation: 460

If I got the question correctly, Something like this should work:

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;

class RenderToFileController extends Controller
{
    public function getName()
    {
        $contents = view('fileview', ['name' => 'foo'])->render();
        file_put_contents("/path/to/file", $contents);
        return $contents;
    }
}

And the fileview template can look the way you want it

Hello {{name}},
how are you today?

Upvotes: 1

Related Questions