تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Scaffolding Render Command0:00

All right, in this video, let me show you how incredibly easy it is to render tabular data. It'll only take a minute. So I have a fresh setup here. We need some kind of command. How about render:command? app, add, new, Acme, render:command. Okay, let's go ahead and set that up. But now I'm going to use a custom file template here. Just think of this as a glorified snippet.

Using Custom File Template0:21

But now I'm going to use a custom file template here. Just think of this as a glorified snippet. They're very easy to set up in most IDEs, and they do save you a huge amount of time, especially for these common types of boilerplate. So the file name will be render.php, the namespace is Acme, the name is render, and the description is render some tabular data. And there you go. Just a little bit of boilerplate to get us going. So now let's render a table in less than a minute. Table, and we're going to instantiate the console helper Table class, and we do need

Building the Console Table0:47

So now let's render a table in less than a minute. Table, and we're going to instantiate the console helper Table class, and we do need to feed it the output here. Okay, now we just set the headers, we set the rows, and we render it. Table, set headers, and how about something very simple like name and age. And next we'll set the rows. This will be an array of data to fill each row. So for example, John Doe is 30, Jane Doe will be 50, and then how about Taylor Otwell, who I think is 28 or 29 at the time of this recording. All right, let's render it, and view this from the terminal.

Running and Recapping Output1:22

I think is 28 or 29 at the time of this recording. All right, let's render it, and view this from the terminal. laravel, and the command name is render, and there you go. It literally couldn't be any simpler than that. So to recap, I told you this was a cinch. We instantiate the Table class, and you want to make sure you feed it your output. Then you need to specify what your header should be, and that'll be displayed right here. And then next, you give it an array of arrays that will represent each row in the table. And then finally, you've set everything up so you can render it to the console.

Next Exercise Preview1:51

And then next, you give it an array of arrays that will represent each row in the table. And then finally, you've set everything up so you can render it to the console. So now that you understand how easy all of this stuff is, in the next lesson, let's work through a little exercise together. Maybe we'll build a little console-based task app, where you can add new tasks, you can view them, and you can complete them all from the console.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟