我對 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,就是這樣:那么這里出了什么問題呢?我搜索了很多但找不到任何有用的東西。因此,如果您知道如何解決此問題,請告訴我。
3 回答

慕絲7291255
TA貢獻1859條經驗 獲得超6個贊
您正在向服務器發送請求,因此需要將 HTTP 請求設置為 post 而不是 get,如下所示
Route::post('/p','PostsController@store');

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
在 create.blade.php 表單方法中是,
POST
但在 web.php 中是Route::get('/p','PostsController@store');
,所以你應該更改Route::post('/p','PostsController@store')
而不是Route::get('/p','PostsController@store')
在控制器中
use Illuminate\Http\Request;
class PostsController extends Controller
{
public function create()
{
return view('posts.create');
}
public function store(Request $request)
{
dd($request->input('image'));
}
}
- 3 回答
- 0 關注
- 154 瀏覽
添加回答
舉報
0/150
提交
取消