–>php artisan make:auth
快速帮助完成登录注册功能的实现
php artisan make:auth
会自动生成相关文件
在views中生成auth文件夹
在controller 中使用auth文件
–>想要使用"laravelcollective/html"的相关功能
要在composer.json的require中添加
"laravelcollective/html": "^5.4.0"`
依赖安装完毕之后,在 config/app.php 中添加:
'providers' => [
Collective\Html\HtmlServiceProvider::class,
],
'aliases' => [
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
],
然后,执行下面 artisan 命令,发布该扩展包配置等项。
php artisan vendor:publish --provider="Collective\Html\HtmlServiceProvider" --force
–>在已有数据库表的基础上,添加一列属性
method: php artisan make:migration add_user_id_to_posts
在add_user_id_to_posts表中添加需要添加的东西
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->integer('user_id');
});
}
public function down()
{
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('user_id');
});
}
执行php artisan migrate
推荐两种富文本编辑器
–>向Textarea 添加编辑器 CKeditor
composer require unisharp/laravel-ckeditor
依赖安装完毕之后,在 config/app.php 中添加:
'providers' => [
Unisharp\Ckeditor\ServiceProvider::class,
],
然后,执行下面 artisan 命令,发布该扩展包配置等项。
php artisan vendor:publish --tag=ckeditor
最后在相应位置添加代码
1.在layout.app文件下中,body尾部添加
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'article-ckeditor' );
</script>
2.在create和edit php 文件中
{{ Form::textarea('body', '', ['id'=>'article-ckeditor','class'=>'form-control','placeholder'=>'Body Text']) }}
添加
'id'=>'article-ckeditor'
–>富文本编辑器
1.要在composer.json的require中添加 "chenhua/laravel5-markdown-editor": "~1.0",
2.composer update
3.composer require chenhua/laravel5-markdown-editor
4.完成上面的操作后,修改 config/app.php 中 providers 数组
Chenhua\MarkdownEditor\MarkdownEditorServiceProvider::class,
5.修改 config/app.php 中 aliases 数组
'MarkdownEditor' => Chenhua\MarkdownEditor\Facades\MarkdownEditor::class,
6.php artisan vendor:publish --tag=markdown
7.在相应的edit 和create php文件内添加相应的代码
示例代码(结合CollectiveHtml):
edit.blade.php:
<div class="form-group">
{{ Form::label('body_label','Body') }}
<div id="test-editormd">
{{ Form::textarea('body', $post->body, ['class'=>'form-control','placeholder'=>'Body Text']) }}
</div>
@include('markdown::encode',['editors'=>['test-editormd']])
</div>
create.blade.php:
<div class="form-group">
{{ Form::label('body_label','Body') }}
<div id="test-editormd">
{{ Form::textarea('body', '', ['class'=>'form-control','placeholder'=>'Body Text']) }}
</div>
@include('markdown::encode',['editors'=>['test-editormd']])
</div>
show.blade.php:
<p class="text-body">
<?php echo MarkdownEditor::parse($post->body); ?>
</p>
完工!