laravel pluck square brackets and double quotes

1

I have the following function that shows a student's course

public function show($id)
{
    $alumno = Alumno::find($id);
    $curso = Matricula::where('id_alumno',$id)->get()->pluck('curso_alumno');
    dd($curso);
    return view('alumnos.show')->with('alumno',$alumno)->with('curso',$curso); 
}

THE method:

public function getCursoAlumnoAttribute()
{
    return $this->curso->nombre. ' - ' . $this->curso->tipo.' / '.$this->curso->created_at->year;
}

But in my view it shows it to me in the following way:

Course ["First Medium A - Scientific Humanist / 2017"]

How can I eliminate those brackets, double quotes, and the duplicate "/" ???

    
asked by Edgardo Escobar 15.06.2017 в 01:26
source

1 answer

0

Do not use the get() method when using Eloquent, you must apply pluck() first and then first() in the collection:

$curso = Matricula::where('id_alumno',$id)->pluck('curso_alumno')->first();

A small improvement to the code, you could use compact() when passing data to the view:

return view('alumnos.show', compact('alumno', 'curso'));
    
answered by 15.06.2017 / 01:42
source