Erro ao retornas Cursos
Erro:
Undefined array key "App\Models\Course"
Model:
class Course extends Model
{
use HasFactory, UuidTrait;
protected $fillable = [
'name',
'description',
'image',
];
}
Controller:
class CourseController extends Controller
{
public function index(){
$courses = Course::all();
return CourseResource::collection($courses);
}
}
Resource:
class CourseResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'image' => $this->image ? Storage::url($this->image) : ''
];
}
api:
Route::get('/courses',[CourseController::class, 'index']);
Segue o repositírio:
https://github.com/acsk/ead-api
Olá, André!
Tudo bem?
Você finalizou o ticket, conseguiu resolver? Tudo certo?
Precisa estar logado para conseguir responder a este ticket!
Clique Aqui Para Entrar!