The father of six-year-old Alesha MacPhail, who was found dead on the Isle of Bute last July, has admitted selling cannabis to the teenager accused of murdering her.

Alesha, from Airdrie in Lanarkshire, was found dead in the grounds of a disused hotel near her grandparents’ seafront home, close to the ferry port of Rothesay, where she had arrived a few days previously to spend a three-week summer break.

Her father, Robert MacPhail, told the high court in Glasgow that the 16-year-old defendant would message him via Facebook and the drugs would usually be handed over at the bus shelter opposite his parents’ flat.

Prosecutors allege that the boy, who cannot be legally named because he is under 18, was armed with a knife when he took the child from her bed, carried her to nearby woodland, then raped and murdered her.

MacPhail said he last sold cannabis to the accused a few months before Alesha’s murder, explaining that he stopped after the teenager’s mother communicated via his partner, Toni McLachlan, that she wanted the drug dealing to stop.

The accused denies all charges, having lodged a special defence of incrimination, blaming McLachlan for Alesha’s death. He also denies attempting to defeat the ends of justice by disposing of clothing and a knife.

Asked how McLachlan got on with his daughter, MacPhail replied: “Great. They both loved each other to bits. Ever since Toni met her, from day one.”

MacPhail told the court that his relationship with Alesha’s mother, Georgina Lochrane, had broken down months after their daughter was born, but that he continued to see Alesha every second weekend and during the holidays, and that she enjoyed visiting Rothesay, going to the beach and playing at the park. “We were never in. We were always doing something.”

MacPhail said that on the night of Alesha’s disappearance he put his daughter to bed and left her with a Peppa Pig DVD before going to sleep in the room he shared with McLachlan. He said: “I told her I would see her in the morning and that was the last time I saw her.”

Alesha’s grandfather, Calum MacPhail, confirmed that his granddaughter would visit Bute regularly. He said that on the night she went missing, her grandmother Angela King left the key in the door. He said in Rothesay many people would leave their doors unlocked.

It was King who reported Alesha missing on Monday 2 July at 6.25am, posting an appeal for help on Facebook and prompting a frantic search by locals on the island. Alesha’s body was found approximately half a mile away by a member of the public at about 9am.

The trial continues.