Too few arguments to function App\Http\Controllers\ProjectController::index(), 0 passed in C:\xampp\htdocs\ContentBaseApp\ - laravel-8

I have error:
ArgumentCountError Too few arguments to function
App\Http\Controllers\ProjectController::index(), 0 passed in
C:\xampp\htdocs\ContentBaseApp\vendor\laravel\framework\src\Illuminate\Routing\Controller.php
on line 54 and exactly 1 expected
In my ProjectController.php How can i solve this
This is my ProjectController.php
public function index($product_id)
{
// $projects = Project::whereIn('product_id',Product::where('user_id',Auth::id())->pluck('id')->toArray())->latest()->paginate(20);
$product = Product::where('user_id', Auth::id())->where('id', $product_id)->firstOrFail();
$projects = Project::where('product_id', $product->id)->latest()->paginate(20);
return view('projects.index', compact('projects'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
I wrote index method code because I want; suppose I have two id 1 & 2 if I click id 1 it will take me to index.blade.php where I can upload new data like data_1 and data_2 those data will show on index.blade.php
And if I click id 2 it will take me to index.blade.php where I don't want to see data of id 1 as I uploaded data1 and data2.
If I upload new data for id 2 I can see those data in index.blde.php

The index function on your ProjectController expects 1 argument ($product_id) as per the error message you're seeing.
Whenever you access of reference the index route, it needs to be provided with the $product_id parameter otherwise an error will be thrown (then one you're seeing).
If you're following convention, what you likely want to do is define two routes:
An index route that displays all resources and takes 0 arguments
A show route that displays information for a single resource and requires 1 argument which identifies a resource.
For example:
web.php
Route::get('/projects', [ProjectController::class, 'index')
->name('projects.index');
Route::get('/projects/{product}', [ProjectController::class, 'show'])
->name('projects.show');
ProjectController.php
public function index()
{
return view('projects.index', [
'projects' => Project::paginate(20),
]);
}
public function show(Product $product)
{
return view('projects.show', [
'projects' => $product->projects()->latest()->paginate(20),
]);
}
If you visit /projects you will return all project resources, but if you visit /projects/2 you will get only the projects related to Product with id of 2.
You can use the route() helper to generate your URLs.
...
That would create a link that would take you to the projects for product 2.

Related

JIKAN API - import data with dynamic ID

I am trying to use this for my import with WPAI in Wordpress. But as a non-developer I have problem to find out, how the "my_get_id" function should looks like.
My first function looks like this
function get_dynamic_import_url() { $id = my_get_id(); return sprintf( "https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[page]=%s&request[per_page]=400", $id ); }
and my "my_get_id" like this
function my_get_id($opt = ""){ $ids = array(1,2,3); return($ids); }
however "my_get_id" is wrong, because it does not return single ID, but an array.
the ID is from 1 - 221
Any idea where should I look, for such a function with return only one ID after another.
Is it possible to implement Rate Limiting- Per Second | 3 requests, otherwise I get 404
thank you for any hint.
regards

Suitescript: copying sublist data from one record to another

I have a before load user event function on an invoice record that create a button called 'create vendor bill'.
When this button is pressed, a new vendor bill record is opened. The UE script:
/**
*#NApiVersion 2.x
*#NScriptType UserEventScript
*/
define([
"N/url",
"N/record",
"N/runtime",
"N/ui/serverWidget",
"N/redirect",
], function (url, record, runtime, serverWidget, redirect) {
var exports = {};
/**
* #param {UserEventContext.beforeLoad} context
*/
function beforeLoad(context) {
if (
context.type == context.UserEventType.EDIT ||
context.type == context.UserEventType.VIEW
) {
var record = context.newRecord;
var recordId = record.id;
var recordType = record.type;
var customer = record.getValue({ fieldId: "entity" });
log.debug("entity", customer);
var scriptObj = runtime.getCurrentScript();
var customForm = scriptObj.getParameter({
name: "custscript_custom_form_vb",
});
var recordSublist = record.getSublist({ sublistId: "item" });
log.debug("item", recordSublist);
var form = context.form;
log.debug("form", form);
var userVarStr = record;
log.debug("uservarstr", userVarStr);
var userVarURL = url.resolveRecord({
recordType: "vendorbill",
params: {
entity: parseInt(customer),
supportcase: recordId,
cf: parseInt(customForm),
},
});
form.addButton({
id: "custpage_button_test",
label: "Create Vendor Bill",
functionName: "getDetails('" + userVarURL + "')",
});
}
}
exports.beforeLoad = beforeLoad;
return exports;
});
Once the page redirects to the vendor bill form, a client script (deployed on the form), sets the field values on the body of the vendor bill using the parameters passed in the url
This is working as expected.
Where I am getting stuck is trying to work out how to pass the 'item' sublist values to from the invoice to the vendor bill?
Would I pass this as an array?
From what I understand, there is a limit to the number of characters that can be passed via the url.
I can't find anything online or in the Netsuite documentation that deals with passing sublist values between records
For starters I would want to see the Client Script.
One option would be to only pass the Invoice Record ID and Type. Then you can create a Suitelet to be used as a proxy and get the sublist data by a saved search.
Something to keep in mind is that if the sublist is very very long you may reach a execution timeout so you may want to consider triggering a MapReduce script to populate the sublist again you would pass it the recType and ID of the invoice and vendor bill and then use a saved search to get the data.
There are other approaches but I would need to see the client script.

Send array of guid in the parameter list of a get request using PostMan

I have a method in my api Controller which have the following signature
[HttpGet]
[Route("api/Controller/GetResult")]
public ApiResult<List<IDocument>> GetResult(DateTime date, Guid id, List<Guid> Ids)
I need to call it using PostMan but I don't know how to send the last argument which is a list of Guid in the parameter list, any help?
you can replace all params with JObject as following :
pass JSON:
{"date":"2019-02-17", "id":"00000000-0000-0000-0000-000000000001", "Ids":["00000000-0000-0000-0000-111111111111", "00000000-0000-0000-0000-222222222222"]}
ACTION:
public ApiResult<List<IDocument>> GetResult(JObject json)
{
DateTime date = json.FirstOrDefault(x => x.Name == "date"))?.Value.ToString(); // simple parameter
//----> output: "2019-02-17"
Guid id = new Guid(json.FirstOrDefault(x => x.Name == "id"))?.Value.ToString()); // simple parameter
//----> output: "00000000-0000-0000-0000-000000000001"
List<JToken> Ids = json.FirstOrDefault(x => x.Name = "Ids")?.Value.ToList(); // list
//----> output: ["00000000-0000-0000-0000-111111111111", "00000000-0000-0000-0000-222222222222"]
//you should specify the type of "JToken" values as this:
List<Guid> IdsList = new List<Guid>();
foreach (var Id in Ids)
{
IdsList.Add(new Guid(Id.Value<string>()));
}
}
You can use postman in-build Dynamic Variable $guid .
This generates a v4 style guid at runtime.
Try this GET request using Postman:
https://httpbin.org/anything?IDs=["{{$guid}}","{{$guid}}","{{$guid}}"]

Laravel 4 - Call to a member function actividads() on a non-object (pivote table)

I'm trying to save in my DB the relation between two tables actividads and fichas (through a pivot table: actividad-ficha. And I'm having this message:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR)
Call to a member function actividads() on a non-object
I pass through my Route two variables (ids):
Route::get('ficha/{id_ficha}/{id_actividad}', array('uses' => 'FichaController#enFicha'));
And then, in my 'FichaController':
public function enFicha($id_ficha, $id_actividad)
{
$ficha = Ficha::find($id_ficha);
// $actividad_id = Actividad::find($id_actividad); (doesnt work)
$actividad_id = $id_actividad;
$ficha->actividads()->sync($actividad_id, false);
return Redirect::route('actividads.index');
}
Here my models:
class Actividad extends Eloquent {
protected $guarded = array();
public function fichas()
{
return $this->belongsToMany('Ficha', 'actividad_ficha')->withTimestamps(); //
}
class Ficha extends Eloquent {
protected $guarded = array();
public function actividads()
{
return $this->belongsToMany('Actividad', 'actividad_ficha')->withTimestamps();
}
After change what #decco and #Ben suggested me, I have the next error message:
Argument 1 passed to Illuminate\Database\Eloquent\Relations\BelongsToMany::formatSyncList() must be of the type array, string given, called in /Applications/XAMPP/xamppfiles/htdocs/webs/lara4/edu1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php on line 578 and defined
I don't know what is wrong with that... Any idea??
Thank you very much!!
$ficha = $id_ficha;
$ficha->actividads()->sync($actividad_id);
There's your problem. $ficha is a String, not an object.
Change the first line with $ficha = Ficha::find($id_ficha) which should return the Ficha object with ID $ficha_id or null.
Also you need to change the second line with $ficha->actividads()->attach($actividad_id).

CodeIgniter: Problem with variable sent to model

I'm inheriting someone else's project and I am trying to familiarize myself with it. I have little experience with CI.
On one of the views there's is a drop down form, on change calls a JS function:
$(document).ready(function()
{
// admin contorller drop down ajax
$("#catagoryDropDownList").change(function()
{
getCatagoriesItems();
});
// initiate table sort
TableSorter.prepareTable($("#dataResultsTable"));
});
// ajax request triggered by catagory drop down menu selection
function getCatagoriesItems()
{
blockPage();
// get base url of current site
var baseurl = $("#site_url_for_ajax").val();
// get adminType
var adminType = $("#admin_type").val();
// get catagory id
var catId = $("#catagoryDropDownList option:selected").attr("id");
var queryString = baseurl + "home/ajaxCatagorySelection/" + catId + "/" + adminType;
$.get(queryString, function(data)
{
var obj = jQuery.parseJSON(data);
// dump data into table when request is successful
$("#dataResultsTable tbody").html(JSONParser.parseHomeDropDownSelectedJSON(obj));
// unblock page when done
$.unblockUI();
});
}
I've logged the two values, catID and adminType, they're both integers, catID will be between 1-10 and adminType = 1. There both references to int values in a database. catID is referencing a field titled 'categoryID'. catID 6 = all. None of the entries in the db have 6 as their value, thus ensuring if you filtered for not equaling 6 you'd get all. They get passed to a function called ajaxCatagorySelection in the controller file home.php. So far, so good. Here's that function:
public function ajaxCatagorySelection($tableName, $id)
{
$vars = new DatabaseRetriever($id);
$resultsArray = $vars->getDataForSpecifiedTable($tableName, $id);
echo json_encode($resultsArray);
}
and that function itself is referencing a model (database_retriever.php) and the class DatabaseRetriever and I'm assuming passing the variables along to the function getDataForSpecifiedTable. I say assuming because the variable names have changed significantly from catID to $tableName and adminType to $id. Here is getDataForSpecifiedTable:
public function getDataForSpecifiedTable($catagoryInfo, $databaseID)
{
// connect to database
$sql = $this->connect($databaseID);
if ($catagoryInfo != 6) {
// build SQL Query and query the database
$result = $sql->query("SELECT fileId, fileTitle, filePath, fileTypeExt, fileDescription, fileModed from admin_files where catagoryId = '" . $catagoryInfo . "' and adminId = '" . $databaseID . "'");
} else {
$result = $sql->query("SELECT fileId, fileTitle, filePath, fileTypeExt, fileDescription, fileModed from admin_files where catagoryId = '" . $catagoryInfo . "' and adminId = '" . $databaseID . "'");
}
// declare array
$items = array();
// retriever rows from database and build array
while ($row = $result->fetch_row())
{
array_push($items, $row);
}
// disconnect from database
$this->disconnect();
// return data in array
return $items;
}
the variable names have changed again but you can tell they are suppose to do what I wrote above by looking at the query. Here's the problem. I added the conditional "if ($catagoryInfo != 6)...", if I don't put the else in there then CI throws out warning errors that no data is being returned. I return $categoryInfo and in the FireBug console I get the correct integer. I've tried the conditional as an integer and a string with both failing. Any ideas what might be happening here?
If database_retriever.php is a model, you should call it like so:
$this->load->model('database_retriever');
$resultsArray = $this->Database_retriever->getDataForSpecifiedTable($tableName, $id);
Also, make sure your model extends Model (or extends CI_Model in CodeIgniter 2).
NOTE: $.getJSON, will auto-parse JSON for you, so you don't need to call parseJSON.