0

i am new to laravel and i am trying to submit form into data base but i am getting error i dont know why i have added the screen shot along with that controller when i do dd($REQUEST->all()) i am getting the form data

<?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());
    
}
}

enter image description here

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');

enter image description here

vivek kn
  • 107
  • 1
  • 18
  • 45

2 Answers2

1

according to your code the controller should look like

<?php

namespace App\Http\Controllers;
use App\Models\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){
    Inventory::Create($request->all());
  }
}
mtopic
  • 126
  • 3
1

change the namesapce of inventory to use App\Models\Inventory;

and also , inside create function use :
Inventory::Create($request->all());