How I can get ids of checked items in items list in backend. I want add extra functionality to publish function. So what I need is to get that checked ids. In (com_registracijos\controllers\lists.php) I tried add something likes this:
function publish()
{
$id = JRequest::getInt('id');
$value = JRequest::getInt('value');
$boxchecked = JRequest::getInt('boxchecked');
}
To get the ids of a list checked itemsyou should get and array instead of an int:
$arrayIDs = JRequest::getVar ( 'cid', null, 'default', 'array' );
Please, note that cid is the name of the check.
Every component, if any, of the resulting array is a checked item id.
If you need a sample, you may check delete uploaded file from an array of id when they are delted in joomla? It is doing a delete, but it will give you the idea.
Regards,
Related
I want to delete multiple string data that is passed by url separated by ','.
Scenario is :
http://127.0.0.1:8888/remove/lui,kui
Through this route lui and kui data that is value of name field in database will be deleted.
My web.php file
Route::get("/remove/{name}",[MyController::class,"remove"]);
MyController.php file
use App\Models\City;
function remove($name){
}
Thanks,your suggestion will be helpful.
You can accomplish this with the following:
//The string of names
$names = "cat,cat,cat,mouse,dog,rabbit";
//We break it down, seperate them by comma, then add them to an array
//After we will get the unique values only of that array
$arrayOfNames = array_unique(explode(',', $names));
//search in the name column for any of these values
//delete if found
//note that you can change the word "name" to any other column name
City::whereIn('name', $arrayOfNames)->delete();
If you have the softdelete trait in your model, and would like to hard delete its: https://laravel.com/docs/9.x/eloquent#soft-deleting
//search in the name column for any of these values
//hard delete if found
City::whereIn('name', $arrayOfNames)->forceDelete();
You can also do an update as well if that is something you are interested in the future:
//search in the name column for any of these values
//update if found
City::whereIn('name', $arrayOfNames)->update(['age' => 123, 'updated_at' => now()]);
Hope it works well for you :)
I use Laravel as an API on an Angular app. One of the controllers has to update an array of objects.
This array, coming from Angular, might have
The same objects but with different attributes
One of the objects might have been deleted
New objects
So, I cannot just update the objects I have, since I need to delete the records that are not on the array any more and also create the new records.
At the moment, I have a not-so-nice solution to delete all the previous records and create new based on the array. Like this:
Sample::where('contest_id', $request->get('contest_id'))
->where('type', '0')
->delete();
$samples = $request->get('samples');
foreach ( $samples as $sample ) {
Sample::create($sample);
}
However, I want to add an activity logger to keep track of changes, but the above solution doesn't help. The activity logger works like this:
activity()
->causedBy($user)
->performedOn($sample)
->withProperties($properties)
->log('update'); //or new or delete
Where $properties is this:
$properties = [
'property' => [
'old' => $old_sample, // empty on creating new record
'new' => $sample // empty on deleting old record
],
];
Anything you could suggest?
Can't you have your frontend also send the sample_id when you need to update the records? If you're able to do that, you could play with Collections and make something like this:
// Retrieves all samples and turn them into a Collection
$samples = collect($request->get('samples'));
// Gets only the sample_ids that are not null and greater than zero
$changed_ids = $samples->pluck('sample_id')->filter()->all();
// These samples are new - create them
$new_samples = $samples->whereStrict('sample_id', null);
// These samples were changed - update them
$changed_samples = $samples->whereIn('sample_id', $changed_ids);
// These samples were deleted - remove them
$deleted_samples = Sample::whereNotIn('sample_id', $changed_ids);
Your solution seems like the most efficient, can you not retrieve the records to be deleted, log them as deleted and then actually delete them, then log the creation of the new ones?
In that scenario, your log is actually a better reflection of the activity that's occured.
I am having trouble while updating session array value in laravel 5. Here is my function,
public function postCartItemAdd()
{
$id = Request::input('id');
Session::push('items', $id);
dd(Session::all());
}
Instead of pushing a new id into the array it just replaces the existing value leaving single item. Am I doing something wrong?
The problem is the session is saved as a flash data. So, you need to save the session whenever you push the data.
$request->session()->push('user.items', 'item1');
$request->session()->push('user.items', 'item2');
$request->session()->save();
or try this
$items = Session::pull('items');
$items[] = $id;
Session::push('items', $items);
umm i think you used it wrong,
see the DOC
it says
Session::push('user.teams', 'developers');
user is the array and we gonna put a value developers to that array with teams key
so then you need to use it in your case as,
Session::push('items.id', $id);
OR if you need to maintain items as an array with default keys like 0,1,2,3... to put the ids, then items should be an array
so there should be a something like,
Session::put('items', []);
then you can use Session::push('items', $id);
if you need to push ids in to same array as you tried.
I need a way to locate a Magento object my multiple attributes. I can look up an object by a single parameter using the 'loadByAttribute' method, as follows.
$mageObj->loadByAttribute('name', 'Test Category');
However, I have been unable to get this to work for multiple parameters. For example, I would like to be able to do the above query using all of the following search parameters. It might look something like the following.
$mageObj->loadByAttribute(array('entity_id' => 128,
'parent_id' => 1,
'name' => 'Test Category'));
Yes, I know that you don't need all of these fields to find a single category record. However, I am writing a module to export and import a whole website, and I need to test if an object, such as a category, already exists on the target system before I create it. To do this, i have to check to see if an object of the same type, with multiple matching attributes already exists, even if it's ID is different.
This may not answer your question, but it may solve your problem.
Magento does not support loadByAttribute for multiple attributes, but instead you can do this.
$collection = $mageObj->getCollection()
->addAttributeToFilter('entity_id', 128)
->addAttributeToFilter('parent_id', 1)
->addAttributeToFilter('name', 'Test Category');
$item = $collection->getFirstItem();
if ($item->getId()){
//the item exists
}
else {
//the item does not exist
}
addAttributeToFilter works for EAV entities (products, categories, customers).
For flat entities use addFieldToFilter.
There is a special case for sales entities (orders, invoices, creditmemos and shipments) that can use both of them.
I have size of product (XS, XL, ...).
I want add column in cart table Size, where show sizes of products.
I added SKU in this table $_item->getSku(); This works.
But $_item->getSize(); not works. Please, help me.
try adding ->addFieldToSelect('*'), it'll add every attribute associated with your products in the returning data, you can replace the * with the attribute code of the attribute your trying to display
problem is, it'll return integers that are used in either eav_attribute_option or eav_attribute_option_value (not sure why there's 2 different tables, one has values and one has sort order, it's not like Magento even links a value to 2 options), however if you use the following code
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('ATTRIBUTE_CODE')->getFirstItem();
$sizeValues = array();
// populates sizevalue array with data
foreach ($attributeOptions as $key => $value)
{
$sizeValues[$value['value']] = $value['label'];
}
you get an array of values with their index's being that of that it returned in your collection