Action Hook: item.create not passing data - directus

I have three action hooks on my 'subscribers' collection in my application:
'item.update.subscribers' => function (array $data) {}
'item.delete.subscribers' => function (array $data) {}
'item.create.subscribers' => function (array $data) {}
and the following filter hook:
'item.create.subscribers:before' => function (\Directus\Hook\Payload $payload) {}
All hooks except for action item.create.subscribers hook work as expected. This is the error I'm getting in the browser console:
if I change the function arg to function ($data), $data is null.

#JRedford - It seems like; there is an issue for storing the data and it's not an issue of hooks.
Can you please confirm once that the data stored successfully in DB?
If yes - then check the logs as #RANGER suggested.

Related

Laravel 8 default RegisterController. Pass parameters in array

I'm trying to create a form for register a user with a Vue component.
I want to use the default routes generated by Auth::routes(); and the default "create" function by the default RegisterController from Laravel 8
This is the create() function I see on RegisterController but it doesn't seem the function that the route is calling.
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return \App\Models\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
But this is the created route:
|POST| register| generated::RuTERdEs1GA9zWNu | App\Http\Controllers\Auth\RegisterController#register| web
Why do I have a create() function if the route points to "register"? What's the function this "register" is actually calling?
The register method is actually part of the Illuminate\Foundation\Auth\RegistersUsers; trait. This is where the validation is called, the user is created, the Registered event is fired and the user is logged in.
It was set up this way to abstract so that the bits your most likely to change are easily available but the other parts of the code which are more essentially/less likely to need updating aren't "cluttering" your controller.

Redux saga pass multiple parameter as action and get it into saga function React native

i want to pass multiple parameters in Redux saga action so i did code as below
this.props.addCartData(_addToCartObject, 'guest')
inside dispatch i am passing like below
addCartData: (value, isFor) => dispatch(addCartRequest(value, isFor)),
in saga function I am accessing as below
function* callAddCart(data, isFor) {
try {
console.log("isFor--->", isFor);
}
}
export function* cartSaga() {
return yield all([
yield takeLatest(actionTypes.ADD_CART_REQUEST, callAddCart),
]);
}
But i log isFor I got undefined can you help me what i making wrong on this ?
it all works around your action creator addCartRequest,
let's say it returns an object like:
function addCartRequest(value, isFor) {
return {
type: actionTypes.ADD_CART_REQUEST,
value,
isFor
};
}
your saga watcher yield takeLatest(actionTypes.ADD_CART_REQUEST, callAddCart), will pass the whole object to callAddCart,
you can access their values assuming the first param as the whole object:
function callAddCart(action) {
console.log("actionType--->", action.type);
console.log("value--->", action.value);
console.log("isFor--->", action.isFor);
}
i created a working example in CodeSandbox:
https://codesandbox.io/s/2021-03-25-redux-saga-action-creator-payload-hk4sb?file=/src/App.js

Laravel middleware with parameter

I write middleare to decide permission. But giving error.
Route page
Route::middleware([Permission::class])->group(function($id){
});
middleware
public function handle(Request $request, Closure $next,$id)
{
$id = $request->id; //$id is returning null
}
Giving this eror
Too few arguments to function App\Http\Middleware\Permission::handle(), 2 passed in /home/saide/Desktop/saide-backoffice/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php on line 167 and exactly 3 expected
I think when you called Middleware you used a square bracket, you have used an array for submitting the parameter to the middleware, use the below code
Route::middleware([Permission::class])->group(function($id){
});
For submitting multiple parameters through middleware use this code:
Route::get('/', function () {
//
})->middleware(['first', 'second']);
For passing single middleware use this:
Route::get('/profile', function () {
//
})->middleware('auth');
Information Source: https://laravel.com/docs/8.x/middleware
The issue is that the middleware is expecting a parameter and you aren't supplying it.
If you want your middleware to have an additional parameter $id, then route should be like this:
Route::middleware([Permission::class.':id_value_goes_here'])->group(function () {
});
If you need the ID to be a dynamic parameter based on a route parameter (e.g. Route::get('/posts/$id', ...)) or something passed to the request, then you should omit the extra parameter from the middleware handle()'s method signature:
public function handle(Request $request, Closure $next)
{
$id = $request->id; // $id will now get correctly set
}

vue.js - Cannot read property 'toLowerCase' of undefined

I am filtering projects with a computed property like this:
filtered_projects() {
return this.projects.filter( (project) => {
return project.title.toLowerCase().indexOf(this.project_filter.toLowerCase()) !== -1
})
}
When I add a new project using this
submitNewProject() {
let path = '/api/projects';
Vue.http.post(path, this.project)
.then( (rsp) => {
this.projects.push(rsp.data);
this.project = this.getSingleProject();
this.create_project = false;
return true;
});
}
This is giving me an error that I can't find
TypeError: Cannot read property 'toLowerCase' of undefined
It may just be that you are not correctly passing the projects data to the projects array.
Firstly vue-resource now uses body not data to get the response, therefore you may need to use:
this.projects.push(rsp.body)
then this will give you a single array item containing all projects which doesn't look like what you want. I believe instead you're after:
this.projects = rsp.body
Assuming the response body is an array of objects this will then allow:
this.projects.filter(project => {})
to work as expected. Meaning project.title should now be valid
EDIT
For a project title to be set to lowerCase you must be returning an object with a title param, i.e.
rsp.body = {
title: 'FOO',
}
which you'd then set on the projects array via:
this.projects.push(rsp.body)
so the first thing to fix is your response, sort your endpoint so it returns what you are expecting, then the rest of the above code should work
You need preserve "this" before Vue.http.post (self=this) and then in callback change this.projects to self.projects.
Explanation:
How to access the correct `this` context inside a callback?

call action of another controller

i have a grid view and i would like to get value of column from another action controller.
at now i have this in controller 1
array(
'name'=>'title',
'value'=>array($this,'Action2'),
),
and i get this error:
controller1 and its behaviors do not have a method or closure named "Action2".
if i replace $this with "controller2"
array(
'name'=>'title',
'value'=>array('controller2','Action2'),
),
i get this error
call_user_func_array() [<a href='function.call-user-func-array'>function.call-user-func-array</a>]: First argument is expected to be a valid callback, 'controller2::action2' was given
maybe this is bad practice but is this feasible?
It's bad practice to use controller actions this way. Better place your code in model's method. But if you still want to do this, here is one way:
'value' => function() {
list($controller) = Yii::app()->createController('controllerId');
return $controller->actionTest();
}
Here is another:
'value' => function() {
$controller = new TestController('test');
return $controller->actionTest();
}
You can use this solution:
Yii::app()->runController('category/view/id/1');