ebook img

Learning Laravel 5 - Building Practical Applications PDF

292 Pages·2016·6.012 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learning Laravel 5 - Building Practical Applications

Learning Laravel 5 Building Practical Applications Nathan Wu ©2015-2016NathanWu Contents Book Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 BookDescription . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 WhatYouWillGet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 BookStructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter1-InstallingLaravel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter2-BuildingOurFirstWebsite . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter3-BuildingASupportTicketSystem . . . . . . . . . . . . . . . . . . . . . . 3 Chapter4-BuildingABlogApplication . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter5-DeployingOurLaravelApplications . . . . . . . . . . . . . . . . . . . . . 3 Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 BookStatus,ChangelogandContributors . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Changelog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 CurrentVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Learning Laravel 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Chapter1:InstallingLaravel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 IntroducingCLI(CommandLineInterface) . . . . . . . . . . . . . . . . . . . . . . . . . 7 CLIforMACOSX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 CLIforWindows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 CLIforLinux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 InstallingLaravelUsingHomestead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 WhatisHomestead? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 HowtoinstallHomestead? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 InstallHomesteadUsingMethod1(requiredComposer) . . . . . . . . . . . . . . . . . 9 InstallHomesteadUsingMethod2(requiresGit) . . . . . . . . . . . . . . . . . . . . . 19 ConfigureHomestead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 LaunchingHomestead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 InstallingLaravel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 CONTENTS Chapter2:BuildingOurFirstWebsite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 ExploringLaravelstructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Understandroutes.php . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 ChangingLaravelhomepage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Addingmorepagestoourfirstwebsite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Createourfirstcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Usingourfirstcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Createotherpages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 IntegratingTwitterBootstrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 UsingBootstrapCDN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 UsingPrecompiledBootstrapFiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 UsingBootstrapSourceCode(Less) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 AddingTwitterBootstrapcomponents . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 LearningBladetemplates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Creatingamasterlayout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Extendingthemasterlayout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 UsingotherBootstrapthemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Refineourwebsitelayouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Changingthenavbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Changingthehomepage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Chapter2Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Chapter3:BuildingASupportTicketSystem . . . . . . . . . . . . . . . . . . . . . . . . . 82 Whatdoweneedtogetstarted? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Whatwillwebuild? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 LaravelDatabaseConfiguration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Createadatabase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Defaultdatabaseinformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 CreateadatabaseusingtheCLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 CreateadatabaseonMac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 CreateadatabaseonWindows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 UsingMigrations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 MeetLaravelArtisan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Createanewmigrationfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 UnderstandSchematowritemigrations . . . . . . . . . . . . . . . . . . . . . . . . . 92 CreateanewEloquentmodel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Createapagetosubmittickets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Createaviewtodisplaythesubmitticketform . . . . . . . . . . . . . . . . . . . . . . 97 InstallLaravelCollectivepackages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 InstallapackageusingComposer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Createaserviceproviderandaliases . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 HowtouseHTMLpackage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 AnoteaboutLaravel5.2’schanges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 CONTENTS Solution1:usewebmiddlewaregroup . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Solution1:fixthe$errorsobject’serror . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Bestsolution:updateyourKernel.phpfile . . . . . . . . . . . . . . . . . . . . . . . . . 109 Submittheformdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Using.envfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Whatisthe.envfile? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Howtoeditit? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Insertdataintothedatabase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Viewalltickets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Viewasingleticket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Usingahelperfunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Editaticket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Deleteaticket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Sendinganemail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 SendingemailsusingGmail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 SendingemailsusingSendgrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Sendingatestemail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Sendinganemailwhenthereisanewticket . . . . . . . . . . . . . . . . . . . . . . . 146 Replytoaticket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 Createanewcommentstable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 IntroducingEloquent:Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 CreateanewCommentmodel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Createanewcommentscontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 CreateanewCommentFormRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Createanewreplyform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Displaythecomments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Chapter3Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Chapter4:BuildingABlogApplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Whatdoweneedtogetstarted? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Whatwillwebuild? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Buildingauserregistrationpage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Creatingalogoutfunctionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Creatingaloginpage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Addauthenticationthrottlingtoyourapplication . . . . . . . . . . . . . . . . . . . . . . 175 Buildinganadminarea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Listallusers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 AllaboutMiddleware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Creatinganewmiddleware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 AddingrolesandpermissiontoourappusingEntrust . . . . . . . . . . . . . . . . . . . 188 InstallingEntrustpackageforLaravel5.2(officialpackage) . . . . . . . . . . . . . . . 188 InstallingEntrustpackageforLaravel5.2(differentbranch) . . . . . . . . . . . . . . . 192 InstallingEntrustpackage(forLaravel5.1) . . . . . . . . . . . . . . . . . . . . . . . . 196 CONTENTS CreateEntrustroles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 Assignrolestousers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 RestrictaccesstoManagerusers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Createanadmindashboardpage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Createanewpost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 CreateaMany-to-Manyrelation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Createandviewcategories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 Selectcategorieswhencreatingapost . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Viewandeditposts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Displayallposts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Editapost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Displayallblogposts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Displayasingleblogpost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 UsingPolymorphicRelations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Seedingourdatabase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Chapter4Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 Chapter5:DeployingOurLaravelApplications . . . . . . . . . . . . . . . . . . . . . . . . 269 Deployingyourappsonsharedhostingservices . . . . . . . . . . . . . . . . . . . . . . . 269 DeployingonGodaddysharedhosting . . . . . . . . . . . . . . . . . . . . . . . . . . 270 DeployingyourappsusingDigitalOcean . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 DeployanewUbuntuserver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 InstallNginx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 InstallMySQLServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 InstallNginx,PHPandotherpackages . . . . . . . . . . . . . . . . . . . . . . . . . . 277 InstallLaravel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 PossibleErrors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 Takeasnapshotofyourapplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 Littletips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Chapter5Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Book Information 1 Book Description Learning Laravel 5: Building Practical Applications is the easiest way to learn web development usingLaravel.Throughout5chapters,instructorNathanWuwillteachyouhowtobuildmanyreal- worldapplicationsfromscratch.Thisbestsellerisalsocompletelyaboutyou.Ithasbeenstructured very carefully, teaching you all you need to know from installing your Laravel 5 app to deploying ittoaliveserver. When you have completed this book you will have created a dynamic website and have a good knowledgetobecomeagoodwebdeveloper. Wefirststartwiththebasics.Youwilllearnsomemainconceptsandcreateasimplewebsite.After thatweprogresstobuildingmoreadvancedwebapplications. Learnbydoing! If you’re looking for a genuinely effective book that helps you to build your next amazing applications,thisisthenumberonebookforyou. Requirements The projects in this book are intended to help people who have grasped the basics of PHP and HTML to move forward, developing more complex projects, using Laravel advanced techniques. ThefundamentalsofthePHParenotcovered,youwillneedto: • HaveabasicknowledgeofPHP,HTML,CSS. • LoveLaravel,likewedo. What You Will Get • Lifetimeaccesstotheonlinebook.(Read70%ofthebookforFREE!) • Digitalbooks:PDF,MOBI,EPUB(PremiumOnly) • Fullsourcecode(PremiumOnly) • Accessnewchaptersofthebookwhileit’sbeingwritten(PremiumOnly) • Acommunityof10000+studentslearningtogether. • Amazingbundlesandfreebiestohelpyoubecomeasuccessfuldeveloper. • iPhone,iPadandAndroidAccessibility. 2 BookDescription 3 Book Structure Note: This book is still under active development, that means some chapters and its content may change. The book also may have some errors and bugs. For any feedback, please send us an email. Thankyou. Chapter 1 - Installing Laravel There are many ways to install Laravel. In this chapter, you will learn how to setup Laravel Homestead(aVagrant-basedvirtualmachine),andrunyourLaravelprojectsonit. Chapter 2 - Building Our First Website Thisbookismeanttohelpyoubuildtheskillstocreatewebapplicationsasquicklyandreliablyas possible. We present you with four projects in various states of completion to explain and practice thevariousconceptsbeingpresented.Ourfirstapp,whichisasimplewebsite,willwalkyouthrough thestructureofaLaravelapp,andshowsomemainconceptsofLaravel.Youwillalsocreateagood templateforournextapplications. Chapter 3 - Building A Support Ticket System After having a good template, we will start building a support ticket system to learn some Laravel features, such as Eloquent ORM, Eloquent Relationships, Migrations, Requests, Laravel Collective, sendingemails,etc. While the project design is simple, it provides an excellent way to explore Laravel. You will also knowhowtoconstructyourappstructuretherightway. Chapter 4 - Building A Blog Application Throughout the projects in this book up to this point, we’ve learned many things. It’s time to use our skills to build a complete blog system. You will learn to make an admin control panel to create andmanageyourposts,users,roles,permissions,etc. Chapter 5 - Deploying Our Laravel Applications Finally, we learn how to create our own web server and deploy our Laravel app to it. Launching yourfirstLaravel5applicationisthateasy! BookDescription 4 Feedback Feedbackfromourreadersisalwayswelcome.Letusknowwhatyoulikedormayhavedisliked. [email protected]. We’realwayshere. Translation We’realsolookingfortranslatorswhocanhelptotranslateourbooktootherlanguages. [email protected]. Hereisalistofourcurrenttranslators: ListofTranslators Book Status, Changelog and Contributors Youcanalwayscheckthebookstatus,changelogandviewthelistofcontributorsat: BookStatus Changelog Contributors Translators

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.