我正在使用 Laravel 8 制作一个在线论坛,在这个项目中,我使用了 this 包,它是一个 Markdown 编辑器,用于解决代码附带的问题。
所以我运行了 composer require michelf/php-markdown
,安装完成后,我尝试使用它说:
<div class="thread-details">
{!! \Michelf\Markdown::defaultTransform($thread->thread) !!}
</div>
但现在的问题是,它什么都不返回作为输出!
那么我该如何解决这个问题?
如果您能与我分享关于此的任何想法或建议,我将不胜感激...
提前致谢。
答案 0 :(得分:1)
启用自动加载.. 我所做的是我跑了
composer require michelf/php-markdown
然后在 vendor/composer/autoload_psr4.php
中我包括...
return array(
...
'Michelf\\' => array($vendorDir.'/michelf/php-markdown/Michelf'),
);
然后在控制器内部
<?php
namespace App\Http\Controllers;
use Michelf\Markdown;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class ListController extends Controller
{
public function index (){
$my_html = Markdown::defaultTransform('*normal emphasis with asterisks*');
$my_html1 = Markdown::defaultTransform('_normal emphasis with underscore_');
$my_html2 = Markdown::defaultTransform('**strong emphasis with asterisks**');
$my_html3 = Markdown::defaultTransform('__strong emphasis with underscore__');
$my_html4 = Markdown::defaultTransform('This is some text *emphased* with asterisks.');
echo $my_html;
echo $my_html1;
echo $my_html2;
echo $my_html3;
echo $my_html4;
}
}
在 web.php 中
<?php
use App\Http\Controllers\ListController;
use Illuminate\Support\Facades\Route;
Route::get('/markdown',[ListController::class,'index']);
然后我运行了 php artisan serve