Comparte:
array must be compatible with Illuminate\Http\Request::user($guard = null) SaveFormRequest
Hola
Estoy retomando este curso luego de una larga pausa.
Tengo este error cuando hago la relacion con el user (author). Es en el video 43 cuando se hago la refactorizacion en la funcino validated, la funcion user, me marca el error mencionado en el asunto.
Estoy retomando este curso luego de una larga pausa.
Tengo este error cuando hago la relacion con el user (author). Es en el video 43 cuando se hago la refactorizacion en la funcino validated, la funcion user, me marca el error mencionado en el asunto.
public function validate()
{
$data = parent::validated()['data'];
$attributes = $data['attributes'];
if (isset($data['relationships'])) {
$relationships = $data['relationships'];
foreach ($relationships as $key => $relationship) {
//dd($key);
$attributes = array_merge($attributes, $this->{$key}($relationship));
}
}
return $attributes;
}
public function user($relationship):array
{
$userUuid = $relationship['data']['id'];
return ['user_id' => $userUuid];
} Les agradezco la ayuda
public function rules()
{
return [
'data.attributes.title' => ['required', 'min:4'],
'data.attributes.slug' => [
'required',
'alpha_dash',
new Slug(),
Rule::unique('articles', 'slug')->ignore($this->route('article')),
],
'data.attributes.content' => ['required'],
'data.relationships.category.data.id' => [
Rule::requiredIf(! $this->route('article')),
Rule::exists('categories', 'slug')
],
'data.relationships.author' => [],
];
}
public function validated($key = null, $default = null)
{
$data = parent::validated()['data'];
$attributes = $data['attributes'];
if ( isset($data['relationships']) ) {
$relationships = $data['relationships'];
foreach ($relationships as $key => $relationship) {
$attributes = array_merge($attributes, $this->{$key}($relationship));
}
}
return $attributes;
}
public function author($relationship): array
{
$userUuid = $relationship['data']['id'];
return ['user_id' => $userUuid];
}
public function category($relationship): array
{
$categorySlug = $relationship['data']['id'];
$category = Category::where('slug', $categorySlug)->first();
return ['category_id' => $category->id ];
}