我是新的laravel,我试图提交表格到数据库,但我得到错误,我不知道为什么我已经添加了屏幕截图沿着与控制器,当我做dd($REQUEST->all())
我得到的表格数据
<?php
namespace App\Http\Controllers;
use App\Inventory;
use Illuminate\Http\Request;
class InventoryController extends Controller
{
public function index(){
return view('invetory.index');
}
public function sales(){
return view('invetory.sale');
}
public function create(Request $REQUEST){
// dd($REQUEST->all());
inventories::Create($REQUEST->all());
}
}
web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/inventory', 'App\Http\Controllers\InventoryController@index')->name('map');
Route::get('/inventory/sales', 'App\Http\Controllers\InventoryController@sales');
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::post('/inventory', 'App\Http\Controllers\InventoryController@create')->name('invetory.create');
3条答案
按热度按时间v09wglhw1#
根据您的代码,控制器应该如下所示:
3bygqnnd2#
将库存的名称空间更改为
use App\Models\Inventory;
另外,在 create**function 用途:中
Inventory::Create($request->all());
kokeuurv3#
您只是忘记在控制器中导入库存模型
在代码顶部添加给定的行,用于调用其他类。
这是函数的样子。
您也可以使用PHP扩展,如PHP IntelliSense和PHP IntelliPhense,以避免此类错误。这些扩展可以为类方法、函数等提供适当的建议。