【发布时间】:2020-12-05 02:13:17
【问题描述】:
我是 Laravel 的新手,我为我的页面制作了一个表单,用户可以添加新图像,这个表单位于 create.blade.php:
<form action="/p" enctype="multipart/form-data" method="post">
@csrf
<div class="row">
<div class="col-8 offset-2">
<div class="row">
<h1>Add New Post</h1>
</div>
<div class="form-group row">
<label for="caption" class="col-md-4 col-form-label">Post Caption</label>
<input id="caption"
type="text"
class="form-control @error('caption') is-invalid @enderror"
name="caption"
value="{{ old('caption') }}"
autocomplete="caption" autofocus>
@error('caption')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="row">
<label for="image" class="col-md-4 col-form-label">Post Image</label>
<input type="file" class="form-control-file" id="image" name="image">
@error('image')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="row pt-4">
<button class="btn btn-primary">Add New Post</button>
</div>
</div>
</div>
这是web.php(路由)文件:
Route::get('/p/create','PostsController@create');
Route::get('/p','PostsController@store');
Route::get('/profile/{user}', 'ProfilesController@index')->name('profile.show');
如您所见,它指的是PostController.php,即:
class PostsController extends Controller
{
public function create()
{
return view('posts.create');
}
public function store()
{
dd(request()->all());
}
}
我也执行命令php artisan route:list,就是这样:
那么这里出了什么问题?我搜索了很多,但找不到任何有用的东西。所以如果你知道如何解决这个问题,请告诉我。
提前致谢
【问题讨论】:
-
只需更改您的路线 - Route::post('/p','PostsController@store');