Original link:www.wjcms.net/archives/la…
Laravel – markdown – editor – the markdown editor
instructions
This expansion pack is compatible with Laravel5.8 and above
The preparatory work
Installing the Extension Package
composer require wjcms/laravel-markdown-editor
Copy the code
Configuration will
/ / cconfig/app. PHP 'will' = > [/ / add the following line of WJCMS \ laravelmd \ LaravelmdServiceProvider: : class,]Copy the code
Copy related files into the project folder
php artisan vendor:publish --provider="wjcms\laravelmd\LaravelmdServiceProvider"
Copy the code
use
1. Introduced in the Blade template
@include('layouts.md.md')
Copy the code
2. Add this parameter to the parent template
Jquery @stack('styles') @stack('scripts')Copy the code
3. Change the imageUploadURL in the md.blade. PHP file to the interface path
4. Create the service uploadService.php and implement the following method:
public function upload(UploadedFile $file) { $path = '/uploads/'.$file->store(date('y/m'), 'uploads'); return $this->save($file, $path); Function save(UploadedFile $file, UploadedFile $file) $path) { return Attachment::create([ 'path'=>$path, 'extension'=>$file->extension(), 'name'=>$file->getClientOriginalName() ]); }Copy the code
5. Admin Controller creation method
*/ public function uploadPic(Request $Request, UploadService $uploadService) { $res = $uploadService->upload($request->file('editormd-image-file')); Return the response () - > json ([' success '= > 1, the' message '= >' photos uploaded successfully ', 'url' = > $res - > path]); }Copy the code
6. Add a route in the routes/web.php file
use App\Http\Controllers\Admin; // Note that this is laravel8, Route::prefix('admin')->name('admin.')->group(function () {Route::post('upload', [Admin\AdminController::class,'uploadPic'])->name('upload'); }Copy the code
You can see that the Markdown editor is ready to use.