Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

martinbean's avatar

Congrats to Cameron BTW!!!

@csuarez Cameron? David Cameron? If so, it’s a sore point for those in the UK who didn’t vote for David Cameron and the Conservative party.

tgif's avatar

I understand. But when you congratulate the candidate you congratulate the process and that is what is important:) There are still countries where there is no choice.

Pendo's avatar
Level 10

So, I made a full post but accidently went backwards in the browser clearing the textarea. Shame on me. So I'll do a little wrap-up to what I was typing.

I just dove head-first into Laravel5. I had some struggles with getting the server up and running, it took me a while before I understood that the Vagrant SSH server I'd setup with Homestead came with all the comments I needed. I faced some mcrypt errors like most people do before I entered the SSH environment. But afterall it works like a charm. Got all things working, the folder mapping, domain names via hosts and even adding the domains using the server command from within the vagrant SSH.

During the past 30 minutes I've made my "first-app". Just some basic testing, used composer for a dependency (Spotify WebAPI), used Sessions, Requests, Redirects, Views, Data within the Views and a custom route. No database so far, but that'll come.

I'm pretty sure I'm not programming in the "Laravel way" yet, but can somebody evaluate this first-time-ever-piece-of-L5-code?

    public function spotify()
    {
        $session = new SpotifyWebAPI\Session('APP_ID', 'APP_SECRET', 'REDIRECT_URI');
        $api = new SpotifyWebAPI\SpotifyWebAPI();

        if( Session::has('spotify.refreshtoken') )
        {
            // Set the access token on the API wrapper
            $session->setRefreshToken( Session::get('spotify.refreshtoken') );
            $session->refreshAccessToken();

            // Set the new token
            $accessToken = $session->getAccessToken();
            $api->setAccessToken( $accessToken );

            $playlists = $api->getUserPlaylists( $api->me()->id , array(
                'limit' => 50
            ));

            // Return a view
            return View('spotify/lists')->with('lists', $playlists->items );

            // Save the new refreshToken to the session
            $refreshToken = $session->getRefreshToken();
            Session::put( 'spotify.refreshtoken', $refreshToken );

        }
        else if( Request::has('code') )
        {
            // Request a access token using the code from Spotify
            $session->requestAccessToken( Request::input('code') );
            $accessToken = $session->getAccessToken();
            $api->setAccessToken( $accessToken );

            // Save the new refreshToken to the session
            $session->refreshAccessToken();
            $refreshToken = $session->getRefreshToken();
            Session::put( 'spotify.refreshtoken', $refreshToken );

            // Send user back to code-less URL
            return redirect('spotify');
        }
        else
        {
            $scopes = array(
                'playlist-read-private',
                'user-read-private'
            );

            $authorizeUrl = $session->getAuthorizeUrl(array(
                'scope' => $scopes
            ));

            header('Location: ' . $authorizeUrl);
            exit();
        }



    }

Since I'm currently working on a complete new way of working I've figured out I'd better start using BitBucket right away. So the next step is to create a private Bitbucket repo with this code and create a copy at my office. Then, I'm going to do some minor changes at the office and push them to the repo and do an update of my local files at home. That's basically the workflow I should be having, right? The office is a simulated-2nd-worker so to say.

Thanks again for all the help! Of course the videos are most usefull, but I really appreciate all the time you've spend helping me so far!

cleanse's avatar

Anyone know why CodeShip breaks my storage permissions after each deploy?

Pendo's avatar
Level 10

Wups... accidently deleted my first project, lol. Had to sell my Macbook Air since it wasn't capable of running homestead with 2GB ram properly. So upgraded to a Macbook Pro. Totally forgot to backup the code directory. Thank god it was just the test project :o

/Edit: Looks like I'm getting the hang of it all. Restored the app quiet quickly!

Pendo's avatar
Level 10

Ok guys, I need some help. Explained as easy as possible. I finished the Laravel 5 Fundamentals videos last week and I decided to explore the L5 documentation before continuing with the intermediate course of L5. The basics of L5 are completely clear to me since I had some knowledge on OOP/MVC before starting, however, ServiceProviders and IoC kind of confuses me.

It's mainly the language and terminology that's making it harder for me to understand then it (hopefully) should be. This is what I currently think to understand:

ServiceProvider: this is the piece of code that I include in my application which makes sure all the required depencies are included. The ServiceProvider has the ability to add dependencies to the IoC container. The IoC Container is the part of the application that takes care of the dependencies when requesting a particular part.

So... if my application needs the class "\Pendo\Car" and this class would require an instance of "\Pendo\CarColor", my SerivceProvider would bind "Car" to "\Pendo\Car" and "CarColor" to "\Pendo\CarColor" in the IoC container. The IoC container on its turn takes car that if I make an instance of "Car", the dependency "CarColor" is automatically injected?

It still kind of confuses me a little bit due to all terms that get thrown to me while learning this part.. but hopefully I'm at least thinking in the right direction.

Pendo's avatar
Level 10

Thanks, looks like I got that right. Maybe my example isn't the best, but at least I got the basics right :)

niczak's avatar

@Pendo - Did you do anything special when installing the spotify-web-api package? I used composer (http://jwilsson.github.io/spotify-web-api-php/) but no matter what I do I can't get Laravel 5 to find the class. Everything looks good w/ autoloader and such. What's at the top of that file before your method?

Pendo's avatar
Level 10

@niczak: wow, sorry! Haven't been much around due to work!

What I think you're missing at the top of your file is this:

use SpotifyWebAPI;
1 like
Previous

Please or to participate in this conversation.