Created
February 27, 2020 11:37
-
-
Save misteryomi/a92792f5325e89825c86eec77dbfe343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InlineEditor | |
.create( document.querySelector( '.editor' ), { | |
toolbar: { | |
items: [ | |
'heading', | |
'|', | |
'bold', | |
'italic', | |
'underline', | |
'alignment', | |
'bulletedList', | |
'numberedList', | |
'|', | |
'link', | |
'blockQuote', | |
'imageUpload', | |
'mediaEmbed', | |
'code', | |
'|', | |
'undo', | |
'redo' | |
] | |
}, | |
simpleUpload: { | |
// The URL that the images are uploaded to. | |
uploadUrl: '/media/upload', | |
// Headers sent along with the XMLHttpRequest to the upload server. | |
headers: { | |
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') | |
} | |
} | |
}) | |
.then( editor => { | |
window.editor = editor; | |
} ) | |
.catch( error => { | |
// console.log( error ); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Validator; | |
class MediaManagerController extends Controller | |
{ | |
function __invoke(Request $request) { | |
$validator = Validator::make($request->all(), [ | |
'upload' => 'image|between:0,2400' | |
]); | |
if ($validator->fails()) { | |
return response(['error' => ['message' => 'The image size must not exceed 2.4mb']]); | |
} | |
$path = $request->upload->store('images'); | |
$fullPath = env('APP_URL').'storage/'.$path; | |
\App\PostMedia::create(['url' => $fullPath, 'created_at' => now()]); | |
return response(['url' => $fullPath]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment