0
votes

Episode 21 in Laravel From Scratch 5.7, the resolved class does not return the value passed to its constructor. It's at 12:30 in the episode, linkk follows: https://laracasts.com/series/laravel-from-scratch-2018/episodes/21

I have tried using full path to the class everywhere it's referenced - but no difference.

Twitter class in App\Services:

.....

<?php

  namespace App\Services;

  class Twitter

{
     protected $apiKey;

     public function _construct($apiKey)

     {
         $this->apiKey = $apiKey;
     }
}

......

It is invoked in web.php: .....

app()->singleton('twitter', function() {

    return new App\Services\Twitter('adsadsadasdfd');
});

......

In ProjectsController (used in Jeffrey Wray's example) the class is invoked like so: .....

use App\Services\Twitter;

......

And then called further down: ......

public function show(Project $project)
    {

        $twitter = app('twitter');
        dd($twitter);
    }
......

This is returned:

>>Twitter {#219 ▼
>>  #apiKey: null
>>}

It should return:

>>Twitter {#219 ▼
>>  #apiKey: "adsadsadasdfd"
>>}
1
Hey lots of great info here but it wasn't very clear what you're asking. Can you summarize the whole proble mat the top without mentioning the lecture. Folks around here aren't going to look at your lecture, just your notes. - chrips

1 Answers

1
votes

Its __construct not _construct ... two underscores __.

PHP Manual - Classes and Objects - Constructors and Destructors