Laravel 6 pathinfo() expects parameter 1 to be string, object given - laravel

This is where i get the error:
$data = Excel::import($path, function($reader) {})->get();
I changed the load() to import(). I want to run this code in Laravel 6, but version 3 of MaatWebsiteExcel does not support load().
I've been searching for solutions, yet i cant find any....
This is my controller:
namespace App\Http\Controllers;
use App\Contact;
use App\CsvData;
use App\Http\Requests\CsvImportRequest;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use Session;
use DB;
class ImportController extends Controller
{
public function getImport()
{
return view('import');
}
function parseImport(CsvImportRequest $request)
{
$path = $request->file('csv_file')->getRealPath();
if ($request->has('header')) {
$data = Excel::import($path, function($reader) {})->get();
} else {
$data = array_map('str_getcsv', file($path));
}
if (count($data) > 0) {
if ($request->has('header')) {
$csv_header_fields = [];
foreach ($data[0] as $key => $value) {
$csv_header_fields[] = $key;
}
}
$csv_data = array_slice($data, 0, 2);
$credentials = $request->file('csv_file')->getClientOriginalName();
$filename = CsvData::all('csv_filename');
if(CsvData::where('csv_filename', '=' ,$credentials)->exists()){
return redirect()->back()->with('alert', 'This specific file has already been imported!');
}
else{
$csv_data_file = CsvData::create([
'csv_filename' => $request->file('csv_file')->getClientOriginalName(),
'csv_header' => $request->has('header'),
'csv_data' => json_encode($data)
]);
}
}
else {
return redirect()->back();
}
return view('import_fields', compact( 'csv_header_fields', 'csv_data', 'csv_data_file'));
}
public function processImport(Request $request)
{
$data = CsvData::find($request->csv_data_file_id);
$csv_data = json_decode($data->csv_data, true);
if(CsvData::where('csv_data', '=' ,$csv_data)->exists()){
return redirect()->back()->with('alert', 'This file has already been imported!');
}
else{
foreach ($csv_data as $row) {
$contact = new Contact();
foreach (config('app.db_fields') as $index => $field) {
if ($data->csv_header) {
$contact->$field = $row[$request->fields[$field]];
} else {
$contact->$field = $row[$request->fields[$index]];
}
}
foreach($contact as $contacts){
$contact->posted_by = $contacts->posted_by;
$contact->employer = $contacts->employer;
$contact->address = $contacts->address;
$contact->barangay = $contacts->barangay;
$contact->citymunicipality = $contacts->citymunicipality;
$contact->province = $contacts->province;
$contact->region = $contacts->region;
$contact->position = $contacts->position;
$contact->job_description = $contacts->job_description;
$contact->salary = $contacts->salary;
$contact->count = $contacts->count;
$contact->work_location = $contacts->work_location;
$contact->nature_of_work = $contacts->nature_of_work;
$contact->min_work_exp_mos = $contacts->min_work_exp_mos;
$contact->min_educ_level = $contacts->min_educ_level;
$contact->coursemajor = $contacts->coursemajor;
$contact->min_age = $contacts->min_age;
$contact->max_age = $contacts->max_age;
$contact->min_height = $contacts->min_height;
$contact->sex = $contacts->sex;
$contact->civil_status = $contacts->civil_status;
$contact->other_qualifications = $contacts->other_qualifications;
$contact->remarks = $contacts->remarks;
$contact->accept_disability = $contacts->accept_disability;
$contact->date_posted = $contacts->date_posted['date'];
$contact->valid_until = $contacts->valid_until['date'];
$contact->date_created = $contacts->date_created['date'];
$contact->last_modified_by = $contacts->last_modified_by['date'];
$contact->date_last_modified = $contacts->date_last_modified['date'];
}
$contact->save();
return view('import_success');
}
}
}
}```

The first parameter of the import() method is not the path to the file anymore in Laravel 3.1, but the class name of the Import file you have to create.
You need to follow below steps to use import method
Step1: Create Import File using below command.
php artisan make:import CsvImport
Step2: Inside CsvImport make changes like this:
namespace App\Imports;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
class CsvImport implements ToCollection
{
public function collection(Collection $rows)
{
return $rows; //add this line
}
}
Step3: In Controller make changes like this:
$path = $request->file('csv_file')->getRealPath();
$rows = Excel::import(new CsvImport, $path);
Reference:
https://docs.laravel-excel.com/3.1/imports/basics.html

I need only those columns after specific indexing, which I consider practically the same use case as described in the question at the top of this page. I propose the following as solution.
$fileArr = (new BulkSampleImport)->toArray($request->file);

Related

A non well formed numeric value encountered in laravel 8

Everything is working fine but after installation of auth package in laravel 8, and after logging into
that website "A non well formed numeric value encountered" error occured in every view. I can't find where is the problem. I also updated from command "composer update" but still error is there.
This is The error image
I need it's answer to reslove this issue.
Below is the Controller Code.
<?php
namespace App\Http\Controllers;
use App\Models\Cart;
use App\Models\Category;
use App\Models\Image;
use App\Models\Product;
use App\Models\state;
use Illuminate\Support\Facades\Auth;
class FrontController extends Controller
{
public function homePage()
{
$popular = Product::inRandomOrder()->limit(8)->get();
$latest = Product::inRandomOrder()->limit(4)->get();
$img = Image::get();
$imgs = Image::orderBy('id','desc')->get();
$categories = Category::where('parent_id',0)->get();
$pimage = [];
foreach ($img as $image) {
if (!isset($pimage[$image->product_id]))
$pimage[$image->product_id] = $image->image;
}
$pimages = [];
foreach ($imgs as $images) {
if (!isset($pimages[$images->product_id]))
$pimages[$images->product_id] = $images->image;
}
$cartCount = 0;
if(Auth::check()){
$cartItems = Cart::join('products','carts.product_id','=','products.id')->where('user_id',Auth::id())->get();
$cartCount = Cart::where('user_id',Auth::user()->id)->count();
return view('pages.index', compact('popular','latest','pimage','pimages','img','cartItems','cartCount', 'categories'));
}
else
return view('pages.index', compact('popular','latest','pimage','pimages','img','cartCount', 'categories'));
}
public function ProductDetail($slug)
{
$product = Product::where('slug',$slug)->first();
$images = Image::where('product_id',$product->id)->get();
$categories = Category::where('parent_id',0)->get();
$cartCount = 0;
if(Auth::check()){
$cartItems = Cart::join('products','carts.product_id','=','products.id')->where('user_id',Auth::id())->get();
$cartCount = Cart::where('user_id',Auth::user()->id)->count();
return view('pages.product_detail', compact('product','images','cartCount','cartItems','categories'));
}
else
return view('pages.product_detail', compact('product','images','cartCount','categories'));
}
public function CartDetail()
{
$img = Image::get();
$categories = Category::where('parent_id',0)->get();
$pimage = [];
foreach ($img as $image) {
if (!isset($pimage[$image->product_id]))
$pimage[$image->product_id] = $image->image;
}
$cartItems = Cart::join('products','carts.product_id','=','products.id')->where('user_id',Auth::id())->get();
$cartCount = Cart::where('user_id',Auth::user()->id)->count();
return view('pages.cart', compact('cartCount','cartItems','pimage','categories'));
}
public function Checkout()
{
$img = Image::get();
$categories = Category::where('parent_id',0)->get();
$pimage = [];
foreach ($img as $image) {
if (!isset($pimage[$image->product_id]))
$pimage[$image->product_id] = $image->image;
}
$state = state::where('country_id',101)->get();
$cartItems = Cart::join('products','carts.product_id','=','products.id')->where('user_id',Auth::id())->get();
$cartCount = Cart::where('user_id',Auth::user()->id)->count();
return view('pages.checkout', compact('cartCount','cartItems','pimage','state','categories'));
}
}
I don't know how without this code on every line of Cart::join, "select('carts.*','product_name')->" the error occured but when i inserted this select statment on specific columns then issue is gets resolved.

Attempt to read property "ref_department_id" on null in laravel 8

My problem is its hard to get the data from relationship field. There is no null value in table but the error shows attempt to read null value.The data connected with api.Its work when i put if and else but i cant figure out the correct solution for this problem.
Here is my function.php line
function getUnitClerk($unit_id){
$unit = Unit::where('id', $unit_id)->first();
$division = Division::where('id', $unit->ref_division_id)->first();
$department = Department::where('id', $division->ref_department_id)->first();
}
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Platform\Bpms;
use Session;
use Illuminate\Support\Facades\DB;
use App\User;
class AdminController extends Controller
{
public function __construct()
{
$this->middleware('guest');
}
public function dashboard()
{
if(!auth()->check())
{
return redirect('login')->with('message', 'Please log in!');
}else{
$roleOfUser = DB::table('role_of_user')->where('user_id','=',auth()->user()->id)->get();
$tasklist = Bpms::queryForTaskListByAssignee(auth()->user()->id);
$list_role = '';
if(count($roleOfUser) > 0){
foreach($roleOfUser AS $roleUser){
if($roleUser != ''){
$grouptasklist = Bpms::queryForTaskList($roleUser->role_name);
$tasklist = array_merge($tasklist, $grouptasklist);
$list_role .= $roleUser->role_name;
$list_role .= ",";
}else{
$tasklist = array();
}
}
}
if(count($tasklist) > 0){
foreach ($tasklist as $i => $task) {
$taskname = $task['taskDefinitionKey'];
$overdue = 'overdue';
if((stripos($taskname, $overdue) !== FALSE)){
$overdue_task2[] = 1;
}else{
$overdue_task2[] = 0;
}
}
$overdue_task = array_sum($overdue_task2);
}else{
$overdue_task = 0;
}
$new = DB::table('history')->where('history_status', '=', 2)->where('history_sender_id','=',auth()->user()->id)->get();
$newtask = count($new);
$inprogress = count($tasklist);
$closed = DB::table('history')
->whereRaw('(history_status = 6)')
->where('created_by','=',auth()->user()->id)
->get();
$closedtask = count($closed);
$lastlogin = DB::table('audit_trail')
->where('adt_action_name', '=', 1)
->where('adt_created_by','=',auth()->user()->id)
->orderBy('adt_created_date', 'desc')
->skip(1)
->take(1)
->first();
// echo '<pre>';
// print_r($tasklist);
// $historyCheck = DB::table('history')->where('history_taskid','=',88989)->exists();
// if($historyCheck)
// {
// $history = DB::table('history')->where('history_taskid','=',88989)->first();
// print_r($history);
// $recordrequest = DB::table('ddms_record_request')->where('ddms_request_id','=',$history->history_request_id)->first();
// print_r($recordrequest);
// exit;
// $requestnumber = DB::table('ddms_request')->where('id','=',$recordrequest->ddms_request_id)->first();
// } else {
// $history = array();
// $recordrequest = array();
// $requestnumber = array();
// }
return view('main.dashboard',compact('tasklist','newtask','inprogress','closedtask', 'overdue_task', 'lastlogin'));
}
}
}
?>
unit model
namespace App\Models\References;
use Illuminate\Database\Eloquent\Model;
class Unit extends Model
{
protected $table = 'ref_unit';
public function division() {
return $this->belongsTo(division::class,'ref_division_id','id');
}
public function section() {
return $this->hasMany(section::class,'ref_unit_id','id');
}
}
Division Model
namespace App\Models\References;
use Illuminate\Database\Eloquent\Model;
class Division extends Model
{
protected $table = 'ref_division';
public function department() {
return $this->belongsTo(department::class,'ref_department_id','id');
}
public function unit() {
return $this->hasMany(unit::class,'ref_division_id','id');
}
}
Department Model
namespace App\Models\References;
use Illuminate\Database\Eloquent\Model;
class Department extends Model
{
protected $table = 'ref_department';
public function tenant() {
return $this->belongsTo('App\Models\References\Tenant','ref_tenant_id','id');
}
public function departmentdetail() {
return $this->hasMany(departmentdetail::class,'ref_department_id','id');
}
public function division() {
return $this->hasMany(division::class,'ref_department_id','id');
}}

Laravel export Maatwebsite/Excel, restructuring the output

Could somebody tell me how to reformat the excel output, so that i get two excel columns. Right now it gives me two arrays in A1 and B1. like two fields with [1,24,5,3.3] and [3,4,5,6], but I want two columns with the numbers.
Route
Route::get('/exporttable/{id}', [TableExportController::class, 'export']);
TableExportController
use Illuminate\Http\Request;
use App\Exports\TablesExport;
use Maatwebsite\Excel\Facades\Excel;
class TableExportController extends Controller
{
public function export(Request $request){
return Excel::download(new TablesExport($request->id), 'tables.xlsx');
}
}
TableExport.php
use App\Models\Tabula;
use Maatwebsite\Excel\Concerns\FromCollection;
class TablesExport implements FromCollection
{
/**
* #return \Illuminate\Support\Collection
*/
function __construct($id) {
$this->id = $id;
}
public function collection()
{
$tabula = Tabula::select('soll', 'haben')->where('id', '=', $this->id)->get();
return $tabula;
}
}
It works with the code of Natvarsinh Parmar - bapu , if you edit the map-function like this
public function map($tabula): array
{
//unformatieren
$soll = $tabula->soll;
//vom string Randwerte abschneiden: [ und ]
$soll = substr($soll, 1, -1);
// in Array umwandeln
$soll = explode( ',', $soll);
//das gleiche mit soll
$haben = $tabula->haben;
$haben = substr($haben, 1, -1);
$haben = explode( ',', $haben);
// als ersten Wert den Header soll/haben einfügen ins Array
array_unshift($haben, "haben");
array_unshift($soll, "soll");
return [
$soll,
$haben
];
}
So now it works, thanks! Each array covers a row in excel now.
Make changes as per below in TableExport.php and check
<?php
namespace App\Exports;
use App\Models\Tabula;
use Maatwebsite\Excel\Concerns\FromArray;
class TablesExport implements FromArray
{
protected $soll;
protected $haben;
protected $export_data;
public function __construct($id)
{
$this->id = $id;
}
public function array(): array
{
$results = Tabula::select('id', 'soll', 'haben')
->where('id', $this->id)
->get();
$this->export_data = [];
$results->each(function($result) {
preg_match_all('!\d+!', $result->soll, $matches_soll);
preg_match_all('!\d+!', $result->haben, $matches_haben);
$this->soll = [];
$this->haben = [];
if(isset($matches_soll[0]))
{
$this->soll = collect($matches_soll[0]);
}
if(isset($matches_haben[0]))
{
$this->haben = collect($matches_haben[0]);
}
if(count($this->soll) > count($this->haben)) {
foreach($this->soll as $key => $val){
$temp = [];
$temp = [
$val,
(isset($this->haben[$key])) ? $this->haben[$key] : ''
];
$this->export_data[] = $temp;
}
} else {
foreach($this->haben as $key => $val){
$temp = [];
$temp = [
(isset($this->soll[$key])) ? $this->soll[$key] : '',
$val
];
$this->export_data[] = $temp;
}
}
});
return $this->export_data;
}
}

Trying to get property 'model_name' of non-object

So I get this error when I'm trying to use the voyager themes, I want to use the voyager's theme since the page is on the admin side so I want to make it uniform.
I realized that I also need to to extend the views so I create this controller
<?php
namespace App\Http\Controllers\Admin;
use App\Models\Toko;
use App\Models\SubOrder;
use Illuminate\Http\Request;
use TCG\Voyager\Facades\Voyager;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use RealRashid\SweetAlert\Facades\Alert;
use Illuminate\Database\Eloquent\SoftDeletes;
use TCG\Voyager\Database\Schema\SchemaManager;
use TCG\Voyager\Http\Controllers\VoyagerBaseController;
class OrderController extends VoyagerBaseController
{
//***************************************
// ____
// | _ \
// | |_) |
// | _ <
// | |_) |
// |____/
//
// Browse our Data Type (B)READ
//
//****************************************
public function index(Request $request)
{
// GET THE SLUG, ex. 'posts', 'pages', etc.
$slug = $this->getSlug($request);
// GET THE DataType based on the slug
$dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first();
// Check permission
$this->authorize('browse', app($dataType->model_name));
$getter = $dataType->server_side ? 'paginate' : 'get';
$search = (object) ['value' => $request->get('s'), 'key' => $request->get('key'), 'filter' => $request->get('filter')];
$searchNames = [];
if ($dataType->server_side) {
$searchable = SchemaManager::describeTable(app($dataType->model_name)->getTable())->pluck('name')->toArray();
$dataRow = Voyager::model('DataRow')->whereDataTypeId($dataType->id)->get();
foreach ($searchable as $key => $value) {
$field = $dataRow->where('field', $value)->first();
$displayName = ucwords(str_replace('_', ' ', $value));
if ($field !== null) {
$displayName = $field->getTranslatedAttribute('display_name');
}
$searchNames[$value] = $displayName;
}
}
$orderBy = $request->get('order_by', $dataType->order_column);
$sortOrder = $request->get('sort_order', $dataType->order_direction);
$usesSoftDeletes = false;
$showSoftDeleted = false;
// Next Get or Paginate the actual content from the MODEL that corresponds to the slug DataType
if (strlen($dataType->model_name) != 0) {
$model = app($dataType->model_name);
if ($dataType->scope && $dataType->scope != '' && method_exists($model, 'scope'.ucfirst($dataType->scope))) {
$query = $model->{$dataType->scope}();
} else {
$query = $model::select('*');
}
// Query menampilkan hanya toko pedagang
if(auth()->user()->hasRole('pedagang')) {
$query->where('user_id', auth()->id());
}
// Use withTrashed() if model uses SoftDeletes and if toggle is selected
if ($model && in_array(SoftDeletes::class, class_uses_recursive($model)) && Auth::user()->can('delete', app($dataType->model_name))) {
$usesSoftDeletes = true;
if ($request->get('showSoftDeleted')) {
$showSoftDeleted = true;
$query = $query->withTrashed();
}
}
// If a column has a relationship associated with it, we do not want to show that field
$this->removeRelationshipField($dataType, 'browse');
if ($search->value != '' && $search->key && $search->filter) {
$search_filter = ($search->filter == 'equals') ? '=' : 'LIKE';
$search_value = ($search->filter == 'equals') ? $search->value : '%'.$search->value.'%';
$query->where($search->key, $search_filter, $search_value);
}
if ($orderBy && in_array($orderBy, $dataType->fields())) {
$querySortOrder = (!empty($sortOrder)) ? $sortOrder : 'desc';
$dataTypeContent = call_user_func([
$query->orderBy($orderBy, $querySortOrder),
$getter,
]);
} elseif ($model->timestamps) {
$dataTypeContent = call_user_func([$query->latest($model::CREATED_AT), $getter]);
} else {
$dataTypeContent = call_user_func([$query->orderBy($model->getKeyName(), 'DESC'), $getter]);
}
// Replace relationships' keys for labels and create READ links if a slug is provided.
$dataTypeContent = $this->resolveRelations($dataTypeContent, $dataType);
} else {
// If Model doesn't exist, get data from table name
$dataTypeContent = call_user_func([DB::table($dataType->name), $getter]);
$model = false;
}
// Check if BREAD is Translatable
$isModelTranslatable = is_bread_translatable($model);
// Eagerload Relations
$this->eagerLoadRelations($dataTypeContent, $dataType, 'browse', $isModelTranslatable);
// Check if server side pagination is enabled
$isServerSide = isset($dataType->server_side) && $dataType->server_side;
// Check if a default search key is set
$defaultSearchKey = $dataType->default_search_key ?? null;
// Actions
$actions = [];
if (!empty($dataTypeContent->first())) {
foreach (Voyager::actions() as $action) {
$action = new $action($dataType, $dataTypeContent->first());
if ($action->shouldActionDisplayOnDataType()) {
$actions[] = $action;
}
}
}
// Define showCheckboxColumn
$showCheckboxColumn = false;
if (Auth::user()->can('delete', app($dataType->model_name))) {
$showCheckboxColumn = true;
} else {
foreach ($actions as $action) {
if (method_exists($action, 'massAction')) {
$showCheckboxColumn = true;
}
}
}
// Define orderColumn
$orderColumn = [];
if ($orderBy) {
$index = $dataType->browseRows->where('field', $orderBy)->keys()->first() + ($showCheckboxColumn ? 1 : 0);
$orderColumn = [[$index, $sortOrder ?? 'desc']];
}
$view = 'voyager::bread.browse';
if (view()->exists("voyager::$slug.browse")) {
$view = "voyager::$slug.browse";
}
// $order = SubOrder::class;
// $items = $order->items;
$tokoId = Toko::select('id')->firstWhere('user_id', auth()->id())->id;
// $orders = SubOrder::where('toko_id', $tokoId)->orderBy('created_at', 'desc')->get();
$orders = SubOrder::with('items')->where('toko_id', $tokoId)->orderBy('created_at', 'desc')->get();
return view('sellers.order.index', compact(
// 'items',
'orders',
'actions',
'dataType',
'dataTypeContent',
'isModelTranslatable',
'search',
'orderBy',
'orderColumn',
'sortOrder',
'searchNames',
'isServerSide',
'defaultSearchKey',
'usesSoftDeletes',
'showSoftDeleted',
'showCheckboxColumn'
));
}
// public function show(SubOrder $order)
// {
// $items = $order->items;
// return view('sellers.order.show', compact('items'));
// }
public function markTolak(SubOrder $suborder)
{
$suborder->status = 'gagal';
$suborder->save();
Alert::info('Order di Proses!', 'Order ditandai proses!');
return redirect('/seller/orders')->withMessage('Order ditandai proses');
}
public function markProses(SubOrder $suborder)
{
$suborder->status = 'proses';
$suborder->save();
Alert::info('Order di Proses!', 'Order ditandai proses!');
return redirect('/seller/orders')->withMessage('Order ditandai proses');
}
public function markDelivered(SubOrder $suborder)
{
$suborder->status = 'selesai';
$suborder->save();
// Check all sub order complete
$pendingSubOrders = $suborder->order->subOrders()->where('status','!=', 'selesai')->count();
if($pendingSubOrders == 0) {
$suborder->order()->update(['status'=>'selesai']);
}
Alert::success('Order Selesai!', 'Order ditandai selesai!');
return redirect('/seller/orders')->withMessage('Order ditandai selesai');
}
}
it shows that the error is from the line 42 where it checks the permission and couldn't find the "model_name". please help
Or maybe if there's another way to use the template?

Too few arguments to function App\Awe\JsonUtility::addNewProduct(),

i am trying to create a CRUD app and am having trouble, if anyone can point me in the right direction i would be grateful, thank you.
Hi there i am having difficulty using data from the json.
i have used it here and it as worked
class JsonUtility
{
public static function makeProductArray(string $file) {
$string = file_get_contents($file);
$productsJson = json_decode($string, true);
$products = [];
foreach ($productsJson as $product) {
switch($product['type']) {
case "cd":
$cdproduct = new CdProduct($product['id'],$product['title'], $product['firstname'],
$product['mainname'],$product['price'], $product['playlength']);
$products[] = $cdproduct;
break;
case "book":
$bookproduct = new BookProduct($product['id'],$product['title'], $product['firstname'],
$product['mainname'],$product['price'], $product['numpages']);
$products[]=$bookproduct;
break;
}
}
return $products;
}
this is my controller
public function index()
{
// create a list.
$products = JsonUtility::makeProductArray('products.json');
return view('products', ['products'=>$products]);
}
this is my route
Route::get('/product' , [ProductController::class, 'index'] );
how can i use this on my controller and what route should i set up to create a product
public static function addNewProduct(string $file, string $producttype, string $title, string $fname, string $sname, float $price, int $pages)
{
$string = file_get_contents($file);
$productsJson = json_decode($string, true);
$ids = [];
foreach ($productsJson as $product) {
$ids[] = $product['id'];
}
rsort($ids);
$newId = $ids[0] + 1;
$products = [];
foreach ($productsJson as $product) {
$products[] = $product;
}
$newProduct = [];
$newProduct['id'] = $newId;
$newProduct['type'] = $producttype;
$newProduct['title'] = $title;
$newProduct['firstname'] = $fname;
$newProduct['mainname'] = $sname;
$newProduct['price'] = $price;
if($producttype=='cd') $newProduct['playlength'] = $pages;
if($producttype=='book') $newProduct['numpages'] = $pages;
$products[] = $newProduct;
$json = json_encode($products);
if(file_put_contents($file, $json))
return true;
else
return false;
}
This is where i am trying to type to code into.
public function create()
{
//show a view to create a new resource
$products = JsonUtility::addNewProduct('products.json');
return view('products', ['products'=>$newProduct], );
}
your function addNewProduct() is expecting 7 parameters when called.
you are getting this error because you cannot provide those parameters that your function is looking for.
in your code above you are passing 'products.json' which is in a string format.
lets assume that it is a JSON data. it will still fail because you are only passing 1 parameter to a function that is expecting 7 parameters.
what you could probably do is change it to
public static function addNewProduct($data)
{
// code here
}
then you can pass your JSON data and then go through each of your json using a loop.

Resources