Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eggplantSword's avatar

Creating/editing a readme file in controller

I'm trying to create a readme file to save content for a documentation page in markdown.

This is what I tried but it just returns true and I can't find the actual file either.

Storage::disk('public')->put(Str::uuid() . '.md', $menu_item['page_content'])

This is how I usually save images but since this isn't an image I'm not sure how to use it

$this->file('image')->store('img/products', 'public');

How can I create this file and get the path to then save in the database? also if I were to edit this file how can I obtain the contents?

0 likes
2 replies
martinbean's avatar
Level 80

@msslgomez Where is the page content coming actually from? If it’s just coming from a form, then you’d just save the string contents to a file with the path of your choosing:

$path = sprintf('%s.md', Str::uuid());
$contents = $request->input('page_content');

Storage::disk('public')->put($path, $contents);

You’d then store the path in your database, so you can retrieve it and get the file contents back:

$contents = Storage::disk('public')->get($page->path);

However, if you’re storing the path in a database, that means you have a database available, so why even bother saving content to Markdown files on disk in the first place? Why not just store the content in the database alongside the rest of the page data?

$page = Page::query()->create([
    'title' => $request->input('title'),
    'content' => $request->input('content'),
]);
eggplantSword's avatar

@martinbean to answer your question... idk that was my suggestion (to store in db) for this but my team thought it was better to put it in a separate file. Thanks for the help

1 like

Please or to participate in this conversation.