Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
Can't pass in data in store method

I cant figure out why I am unable to pass in the "name" in my store method.
this line:- 'name' => $id->name,
I did check and the variable is not null.

Here's My Controller:-

$id = DB::table('friends')
      ->where('created_by', '=', $request->created_by)
      ->where('friends_id', '=', auth()->id())
      ->first();
      dd($id->name);
  if ($id && $id->friends_id == auth()->id()) {

      Post::create([
            'title'=>$data['title'],
            'body'=>$data['body'],
            'created_by'=>$request->created_by,
            'user_id'=>Auth::user()->id,
            'filled_by'=>Auth::user()->uuid,
            'name' => $id->name,

          ]);


  } else {

     Post::create([
            'title'=>$data['title'],
            'body'=>$data['body'],
            'created_by'=>$request->created_by,
            'user_id'=>Auth::user()->id,
            'filled_by'=>Auth::user()->uuid,

          ]);
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Make sure, in Post the column name field is fillable.

protected $fillable = [
    'title','body','created_by','user_id','filled_by','name'
];

I would recommend you to follow this way of your if condition.

$post = [
    'title'=>$data['title'],
    'body'=>$data['body'],
    'created_by'=>$request->created_by,
    'user_id'=>Auth::user()->id,
    'filled_by'=>Auth::user()->uuid
]

if ($id && $id->friends_id == auth()->id()) {
    $post['name'] = $id->name;
}

Post::create($post);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda