laravel summernote backend
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\Shared; | |
use App\Http\Controllers\Controller; | |
use App\Http\Requests\Summernote\SummernoteDeleteRequest; | |
use App\Http\Requests\Summernote\SummernoteUploadRequest; | |
use Storage; | |
class SummernoteController extends Controller | |
{ | |
public function upload(SummernoteUploadRequest $request) | |
{ | |
$images = []; | |
foreach ($request['files'] as $image) { | |
$img = $image->store('summernote'); | |
$images[] = $img; | |
$pic = \Image::make('storage/' . $img); | |
$width = $pic->width(); | |
if($width > 800) { | |
$pic->resize(800, null, function ($constraint) { | |
$constraint->aspectRatio(); | |
}); | |
} | |
$pic->save(); | |
} | |
return $images; | |
} | |
public function delete(SummernoteDeleteRequest $request) | |
{ | |
return Storage::delete($request['file']); | |
} | |
} |
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\Requests\Summernote; | |
use Illuminate\Foundation\Http\FormRequest; | |
class SummernoteDeleteRequest extends FormRequest | |
{ | |
/** | |
* Determine if the user is authorized to make this request. | |
* | |
* @return bool | |
*/ | |
public function authorize() | |
{ | |
return true; | |
} | |
/** | |
* Get the validation rules that apply to the request. | |
* | |
* @return array | |
*/ | |
public function rules() | |
{ | |
return [ | |
'file' => 'string', | |
]; | |
} | |
} |
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\Requests\Summernote; | |
use Illuminate\Foundation\Http\FormRequest; | |
class SummernoteUploadRequest extends FormRequest | |
{ | |
/** | |
* Determine if the user is authorized to make this request. | |
* | |
* @return bool | |
*/ | |
public function authorize() | |
{ | |
return true; | |
} | |
/** | |
* Get the validation rules that apply to the request. | |
* | |
* @return array | |
*/ | |
public function rules() | |
{ | |
return [ | |
'files.*' => 'image', | |
]; | |
} | |
} |
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
Route::post('summernote/upload', [SummernoteController::class, 'upload'])->name('summernote.upload'); | |
Route::post('summernote/delete', [SummernoteController::class, 'delete'])->name('summernote.delete'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment