如果我在文本编辑器中放置对齐文本或上传图片,我只会收到错误 405 Method Not Allowed,即使路由已发布,本地项目一切正常,但已经在我拥有的服务器上这个问题
我已经将路由更改为“匹配”、“任何”,我已经通过 Ajax 请求完成了,我调整了中间件,我试图通过 htccess 停用 ModSecurity,我更改了文本编辑器,我使用了 TinyMCE、CKEDITOR、QUILLJS , TRIX EDITOR, 并且都存在同样的问题。如果我使用 any 或 match 方法离开路由,它不再返回 405 错误,而是发送一个空负载;
我的路线:
Route::get('/dashboard/new-project', 'BackofficeController@getNewProject')->name('backoffice.new-project');
Route::post('/dashboard/projects', 'BackofficeController@createNewProject')->name('process.create.new.project');
我的控制器:
public function getNewProject(){
$project_type = Project_type::all();
$products = Product::with([
'sub_category' => function ($query) {
$query->with([
'sub_category_languages' => function ($query) {
$query->where('language_id', '=', 1);
},
'category' => function ($query) {
$query->with([
'category_languages' => function ($query) {
$query->where('language_id', '=', 1);
}
]);
}
]);
}
])
->where('is_active', '=', true)
->where('is_deleted', '=', false)
->orderBy('name', 'ASC')
->get();
return view('backoffice.new-project', compact('project_type', 'products'));
}
public function createNewProject(Request $request){
$request->validate([
'slug' => 'required',
'category' => 'required',
'published_at' => 'required | date',
'is_active' => 'required |boolean',
'title' => 'required',
'description'
]);
if(Projects::where('slug', request('slug'))->exists()) {
return back()->with('msg', 'This title already exists')->withInput();
} else {
$project = Request([
'slug' => 'slug',
'category' => 'category',
'meta_description' => 'meta_description',
'key_words' => 'key_words',
'published_at' => 'published_at',
'is_active' => 'is_active'
]);
//save project in DB
Projects::create($project);
}
$project_languages = Request([
'title' => 'title',
'sub_title' => 'sub_title',
'description' => 'description'
]);
// save project language in DB
$lastProject = BackofficeRepository::getLastProject();
$projectId = $lastProject->id;
$project_languages['projects_id'] = $projectId;
Projects_languages::create($project_languages);
//save products relashionatips in DB
foreach ($request->get('products') as $product_id) {
$projects_products = new Projects_products();
$projects_products->product_id = $product_id;
$projects_products->projects_id = $projectId;
$projects_products->save();
}
//thumbnail image upload
$path = $request->file('image');
$custom_name_file = $request->slug . '-' . 'thumbnail' . '.jpg';
$folder_thumbnail = 'img/inspirations/thumbnails/' . $request->slug;
$path->move($folder_thumbnail, $custom_name_file);
//banners upload
$files = $request->file('banner');
$folder_banners = 'img/inspirations/banners/' . $request->slug;
if(!empty($files)):
$i = 0;
foreach($files as $file):
$i++;
$custom_name_banner = $request->slug . '-' . 'banner' . '-'. $i . '.jpg';
$file->move($folder_banners, $custom_name_banner);
endforeach;
endif;
return redirect('/dashboard/all-inspirations')->with('msg', 'Project created success!');
带有 ajax 函数的表单(如果需要)
<div class="container-fluid">
<div class="row m-0">
<div class="col-12">
<div class="col-12 my-3">
<h3 class="mb-2 text-uppercase" style="color: #89bab6;font-size:2rem !important;text-align:center"><b>Create a new project</b></h3>
</div>
<div class="col-md-12">
<form id="form-create" method="post" accept-charset="utf-8" enctype="multipart/form-data">
@csrf
<div class="row m-0">
<div class="form-group col-6 pl-0 pr-2">
<label for="title">Title:</label>
<input type="text" class="form-control" value="{{ old('title') }}" id="title" name="title" placeholder="Insert title to project" onblur="showSlug()" required>
</div>
<div class="form-group col-6 pr-0 pl-2">
<label for="sub_title">Sub Title:</label>
<input type="sub_title" class="form-control" value="{{ old('sub_title') }}" id="sub_title" name="sub_title" placeholder="Insert sub title to project">
</div>
</div>
<p id="slug-text">https://circu.net/inspirations/</p>
<div class="form-group d-none">
<label for="slug">Slug:</label>
<input type="text" class="form-control" value="{{ old('slug') }}" id="slug" name="slug" placeholder="Insert the slug to project. Ex: project-circu-magical-furniture">
</div>
<div class="form-group">
<textarea name="description" id="description" rows="15" placeholder="Insert your project content">{{ old('description') }}</textarea>
</div>
<div class="form-group">
<label for="date">Date:</label>
<input type="date" class="form-control" value="{{ old('date', date('Y-m-d')) }}" id="published_at" name="published_at" required>
</div>
<div class="form-group row m-0">
<label for="is_active" class="p-0">Category:</label>
@foreach($project_type as $category)
<div class="form-group col-4 d-flex">
<input type="checkbox" name="category[]" id="category" value="{{$category->name}} {{ old('category[]') }}" style="display:block;width:15px">
<p class="ml-3 mb-0">{{$category->name}} </p>
</div>
@endforeach
</div>
<div class="form-group">
<label for="products">Select products:</label>
<select class="select-product" required multiple="multiple" name="products[]" id="products" data-live-search="true" data-maximum-selection-length="4">
@foreach ($products as $product)
<option value="{{$product->id}}">
{{$product->name}} {{$product->sub_category->sub_category_languages[0]->name}}
</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="meta">Meta Description:</label>
<textarea name="meta_description" id="meta_description" cols="30" rows="2" maxlength="200" placeholder="Insert the meta description to project">{{ old('meta_description') }}</textarea>
<div class="d-flex justify-content-end align-items-center">
<span id="charCounter1" style="text-transform:lowercase;">200</span>
</div>
</div>
<div class="form-group">
<label for="key_words">Key Words:</label>
<textarea name="key_words" id="key_words" cols="30" rows="2" maxlength="200" placeholder="Insert the key words to project">{{ old('key_words') }}</textarea>
<div class="d-flex justify-content-end align-items-center">
<span id="charCounter2" style="text-transform:lowercase;"></span>
</div>
</div>
<div class="form-group row m-0">
<label for="is_active" class="p-0">Project is actived?</label>
<div class="form-group col-4 d-flex">
<input type="checkbox" name="is_active" id="is_active" onclick="checkedBox(this)" value="1" style="display:block;width:15px" checked>
<p class="ml-3 mb-0">Yes</p>
</div>
<div class="form-group col-4 d-flex">
<input type="checkbox" name="is_active" id="is_active" onclick="checkedBox(this)" value="0" style="display:block;width:15px">
<p class="ml-3 mb-0">No</p>
</div>
</div>
<div class="form-group">
<div class="row m-0">
<div class="col-8 p-0">
<label for="image">Thumbnail image: *please insert a image with dimensions: 850x950</label>
<input type="file" class="form-control" id="image" name="image" accept="image/*" required>
</div>
<div class="col-4 px-4">
<img src="" alt="" class="preview-img" style="max-width: 89px; max-height: 100px">
</div>
</div>
</div>
<div class="form-group">
<label for="image">Banner image: *please insert a image with dimensions: 500x600 or 1200x600</label>
<input type="file" class="form-control" id="banner" name="banner[]" accept="image/*" multiple required>
</div>
<div class="col-12 p-0 m-auto d-flex justify-content-between">
<a class="btn-primary btn" href="{{url()->previous()}}" style="border-radius: 0.50rem; padding: 10px 24px"> < BACK </a>
<button class="btn bg-gradient-success" type="submit" id="btn-ajax" aria-hidden="true">SAVE</button>
</div>
</form>
</div>
</div>
</div>
</div>
{{-- <script src="https://cdn.ckeditor.com/4.21.0/full/ckeditor.js"></script> --}}
{{-- <script src="/js/backoffice/ckeditor/ckeditor.js"></script> --}}
@endsection
@section('footer-scripts')
{{-- <script type="text/javascript" src="https://unpkg.com/[email protected]/dist/trix.umd.min.js"></script>--}}
<script src="https://cdn.tiny.cloud/1/my9ztv3a3drx46ktolxf8hdqvfrd28mzr2tolcfv2vdwy24u/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>
<script>
$(document).ready(function(){
$('#btn-ajax').click(function(e){
e.preventDefault();
// var formData = new FormData(document.getElementById("form-create"));
var formData = new FormData($('#form-create'));
console.log(formData);
var content = tinymce.get("description").getContent();
var url = '{{route("process.create.new.project")}}';
$.ajax({
url: url,
method: 'POST',
data: formData,
dataType: 'JSON',
contentType: false,
cache: false,
processData: false,
success:function(response)
{
alert(response.success)
},
error: function(response, error) {
console.log(response)
alert(error)
}
});
});
});
即使我直接通过Laravel发帖,我也有同样的问题
我不知道还能做什么,有人可以帮我吗?