Im doing this project which I want to let the admin user to create custome pages for the website.
Is it possible to instead of saving users request in database, have a button in my createpage.blade.php that when user press it, it'll create a blade for me in views folder which holds users request?
P.S: also I want it to create a route in web.php but this one is not a matter of importance
CodePudding user response:
So according to your need, You may use summernote or any WYSIWYG editor to write and store HTML/CSS/JS plain code in the database and then use one blade file to load the content and render it using this syntax on blade
{!! !!}
But if it's user generated content, you must read this warning
Be very careful when echoing content that is supplied by users of your application. You should typically use the escaped, double curly brace syntax to prevent XSS attacks when displaying user supplied data.
Update: You may use third parties packages to protect your code https://github.com/mewebstudio/Purifier
Further reading here https://laravel.com/docs/8.x/blade#displaying-unescaped-data
CodePudding user response:
Yes, you can create page dynamically in Laravel by using Storage::put()
method. Try this code:
$pageContent = "@extends('layouts.app')
@section('title', '".\Request::input('page_name')."')
@section('page-header')
<h1>
'".\Request::input('page_name')."'
</h1>
@endsection
@section('content')
<div class='container'>
'".\Request::input('page_content')."'
</div>
@endsection
@section('script')
<script>
</script>
@endsection
@section('style')
<style>
</style>
@endsection
";
$project_name = 'your_project_name';
\Storage::disk('disk_path')->put($project_name.'/resources/views/new-page.blade.php', $pageContent);
And add this disk to your filesystem.php under disks:
'disk_path' => [
'driver' => 'local',
'root' => 'E:\xampp\htdocs',
'visibility' => 'public',
],
And use fopen()
for write Routes in web.php