Laravel vs Lumen (Taylor Otwell' review)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi this is Taylor OTT well back with another laravel screencast in this screencast I'd like to introduce you to lumen the latest member of the laravel family lumen is the official micro framework of laravel and it's blazingly fast it's a great way to write micro services or small api's using the laravel syntax you love but with an extremely fast framework so many times if you had your primary laravel application but you wanted to support it with some micro services or other supporting services you had to reach or something like Silex or slim and use a different syntax and not the same libraries you're used to and sometimes you know requires quite a bit of extra work to get your database in cache and all that set up with lumen you get the power of all of Larry Bell's convenient components so eloquent database caching even Redis caching all of that is ready to go out of the box and it's still faster than those other options so it's a great choice to support your laravel applications now let me show you what it looks like I've got a default lumen installation here and you can see that the folder structure is a little slimmer there's no resources directory and no database directory out of the box but we do have the familiar app HTTP routes and you'll see we're just using a closer route by default although you can use controllers with full dependency injection in lumen so you can have that power as well as you want and of course you can do middleware to protect your routes and do some filtering before the request enters your application alright so writing a lumen route is just like riding a laravel write route we can just return hello world right here and we'll call that in our browser and we get hello world and of course it's very fast now what's great is let's go ahead and pull some data from the database and we'll show you how easy this is to do in lumen all right so if I go to my environment file that's where you're going to configure your lumen application there's not a config directory with seven or eight files so you just have the one environment file and you can use the dot F library that laravel uses or you can load your in environment variables through in genetics or through some other means on your production server all right so I've already got my database configured for homestead as you can see so let's go ahead and make a table in what's really cool about lumen is there's also some artisan commands that ship with lumen so let me show you that all right now if I do PHP artisan list you can see that I have some migration commands and then also the queue command so lumen is also a very light queue worker and can even queue jobs itself just like the full laravel framework because queues are really such an a big part of modern web applications it makes sense for lumen to be able to push and consume queue messages from itself all right so let's go ahead and make a migration just to make a simple table and we'll get started so PHP artisan and first what we need to do is actually make that database folder because it's not there by default so how I do that is PHP artisan make database all right and you'll see that created a database folder with a migrations directory and a seeds directory so we can seed our database all right I'm going to head back to my terminal and now we're ready to make our migration so let's create users table and give it that table name all right and that migration has been created now what we will need to do is I'll actually add that to our autoloading setup so we're going to class map that and we can just put database here alright and then we need to regenerate our auto loading files all right so we should be ready to do this migration let's go ahead and go into the file and let's add a couple fields here maybe an email address and of course our time stamps that's really all we need for now for this demo alright we're almost ready to run this migration the last thing we need to do is uncomment a few lines in our bootstrap app file so if I go to this file I need to uncomment this dot env load command and what that does is actually load our environment variables into the environment and of course in your production server you can do this any way you want via Engine X or some other means for loading environment variables now I also need to uncomment this app with facades that's going to make our migration be able to use the schema facade to create our table alright so once I have those two things uncommented I should be ready to run my migration so let's hop back over to the terminal now I need to be in my VM since that's where my database lives is in Homestead and I'm ready to run PHP artisan migrate and will force that to run all right and so our user table has been created so that's great all right now let's use eloquent to actually put some data into the database now the first thing I need to do is actually enable eloquent because eloquent is not enabled out of the box so I can do that again in my bootstrap app file I'm just going to uncomment app with eloquent and that's going to bootstrap eloquent win my application loads all right so now let's go to our routes file and we'll just create a simple model right here just for this demo all right so let's create a user model and that extends illuminate database eloquent model all right and we don't need to set a table name because eloquent can figure that out for us now let's create a new user and set the email address to Taylor at laravel com and we will save that user and return all done all right and now let's go ahead and call this route and see if our user is created alright then it says all done so let's check our database you can see if i refresh this here we have a user's table and there's our user right there in the database so we're already using the power of eloquent with lumens so let's go ahead and return some eloquent data back out from this realm all right if we look in our database that is user ID one so let's go ahead and make another route with user ID so we can accept the parameter here and we're just going to return user find or fail ID so really simple route to just get the user from the database and throw it back out on the page so let's call that route all right user 1 and as you can see just like laravel we get the JSON of the user that easy it couldn't be simpler to start building api's with lumen and eloquent and you can even throw caching into the mix very easily all right so let's call a user that we don't have in the database and you can see we are going to get a 404 exception and you get the full nice symphony error response when something goes wrong in lumen so you're fully up to speed on what happened in your application alright so that's how easy it is to get started with lumen and eloquent and of course we can use caching and even queue jobs with the power of this micro framework and have amazing speed
Info
Channel: Software Development Company Belitsoft
Views: 23,584
Rating: undefined out of 5
Keywords: Laravel vs Lumen, laravel, lumen
Id: WzD9BXIKHCE
Channel Id: undefined
Length: 7min 18sec (438 seconds)
Published: Wed Sep 28 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.