\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{FrancoSvalvast} \pdfinfo{ /Title (laravel-7.pdf) /Creator (Cheatography) /Author (FrancoSvalvast) /Subject (laravel 7 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{laravel 7 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{FrancoSvalvast} via \textcolor{DarkBackground}{\uline{cheatography.com/145313/cs/35392/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}FrancoSvalvast \\ \uline{cheatography.com/francosvalvast} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 12th November, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Project command}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.14471 cm} x{3.83229 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{update data tables}} \tn % Row 0 \SetRowColor{LightBackground} Update table & php artisan make:migration \seqsplit{add\_comment\_to\_products\_table} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} add col & \$table-\textgreater{}text('comment'); \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.94103 cm} x{3.03597 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{SEED}} \tn % Row 0 \SetRowColor{LightBackground} Use factory on seed & Product::factory(10)-\textgreater{}create(); \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} run seed & php artisan db:seed \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} run seed and migrate & php artisan migrate -{}-seed \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{ELOQUENT ORM}} \tn % Row 0 \SetRowColor{LightBackground} New Element & \$flight = new Flight; \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Find Element & \$flight = Flight::find(1); \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} Update Element & \$flight-\textgreater{}name = 'New Flight Name'; \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} Save Element & \$flight-\textgreater{}save(); \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} Create inline & \$user = User::create({[}'first\_name' =\textgreater{} 'Taylor','last\_name' =\textgreater{} 'Otwell'{]}); \tn % Row Count 10 (+ 4) % Row 5 \SetRowColor{white} Update All & Flight::where('active', 1)-\textgreater{}update({[}'delayed' =\textgreater{} 1{]}); \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} Delete & \$current\_user.delete(); \tn % Row Count 14 (+ 1) % Row 7 \SetRowColor{white} Delete by id & User::destroy(1); \tn % Row Count 15 (+ 1) % Row 8 \SetRowColor{LightBackground} Delete all & \$deletedRows = Flight::where('active', 0)-\textgreater{}delete(); \tn % Row Count 18 (+ 3) % Row 9 \SetRowColor{white} Get All & \$items = Item::all() \tn % Row Count 19 (+ 1) % Row 10 \SetRowColor{LightBackground} Find one by primary key & \$flight = Flight::find(1); \tn % Row Count 21 (+ 2) % Row 11 \SetRowColor{white} display 404 if not found & \$model = Flight::findOrFail(1); \tn % Row Count 23 (+ 2) % Row 12 \SetRowColor{LightBackground} Get last entry & \$items = Item::latest()-\textgreater{}get() \tn % Row Count 25 (+ 2) % Row 13 \SetRowColor{white} Chain & \$flights = App\textbackslash{}Flight::where('active', 1)-\textgreater{}orderBy('name', 'desc')-\textgreater{}take(10)-\textgreater{}get(); \tn % Row Count 29 (+ 4) % Row 14 \SetRowColor{LightBackground} Where & Todo::where('id', \$id)-\textgreater{}firstOrFail() \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{ELOQUENT ORM (cont)}} \tn % Row 15 \SetRowColor{LightBackground} Like & Todos::where('name', 'like', '\%' . \$my . '\%')-\textgreater{}get() \tn % Row Count 3 (+ 3) % Row 16 \SetRowColor{white} Or where & Todos::where('name', 'mike')-\textgreater{}orWhere('title', '=', 'Admin')-\textgreater{}get(); \tn % Row Count 6 (+ 3) % Row 17 \SetRowColor{LightBackground} Count & \$count = Flight::where('active', 1)-\textgreater{}count(); \tn % Row Count 8 (+ 2) % Row 18 \SetRowColor{white} Sum & \$sum = Flight::where('active', 1)-\textgreater{}sum('price'); \tn % Row Count 10 (+ 2) % Row 19 \SetRowColor{LightBackground} Contain & if (\$project-\textgreater{}\$users-\textgreater{}contains('mike')) \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Create a table}} \tn % Row 0 \SetRowColor{LightBackground} Create data table & {\bf{php artisan make:migration create\_products\_table}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Foreign Key relation & {\bf{ \$table-\textgreater{}foreignId('user\_id')-\textgreater{}constrained('users')-\textgreater{}onDelete('cascade');}} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} Default value & {\bf{ \$table-\textgreater{}boolean('isActive')-\textgreater{}default(true); }} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} Not required & {\bf{\$table-\textgreater{}text('description')-\textgreater{}nullable();}} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} Unique constraint & {\bf{ \$table-\textgreater{}string('modelNo')-\textgreater{}unique();}} \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Factory}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{database/factories/ProductFactory}.php & public function definition() \{ return {[} 'name' =\textgreater{} \$this-\textgreater{}faker-\textgreater{}text(20), 'price' =\textgreater{} \$this-\textgreater{}faker-\textgreater{}numberBetween(10, 10000), {]}; \tn % Row Count 8 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Routes}} \tn % Row 0 \SetRowColor{LightBackground} Basic route closure & \seqsplit{Route::get('/greeting'}, function () \{ return 'Hello World'; \}); \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Route direct view shortcut & \seqsplit{Route::view('/welcome'}, 'welcome'); \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} Route to controller class & Route::get('/user','usercontroller@index'); \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} Route only for specific HTTP verbs & Route::match({[}'get', 'post'{]}, '/', function () \{ // \}); \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} Route for all verbs & Route::any('/', function () \{ // \}); \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} Route Redirect & \seqsplit{Route::redirect('/clients'}, '/customers'); \tn % Row Count 16 (+ 2) % Row 6 \SetRowColor{LightBackground} Route Parameters & Route::get('/user/\{id\}', function (\$id) \{ return 'User '.\$id; \}); \tn % Row Count 20 (+ 4) % Row 7 \SetRowColor{white} Optional Parameter & Route::get('/user/\{name?\}', function (\$name = 'John') \{ return \$name; \}); \tn % Row Count 24 (+ 4) % Row 8 \SetRowColor{LightBackground} Named Route & Route::get( '/user/profile', {[}UserProfileController::class, 'show'{]} )-\textgreater{}name('profile'); \tn % Row Count 29 (+ 5) % Row 9 \SetRowColor{white} Resource & \seqsplit{Route::resource('photos'}, \seqsplit{PhotoController::class);} \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Routes (cont)}} \tn % Row 10 \SetRowColor{LightBackground} Resourse Short & \seqsplit{Route::resource('photos'}, 'PhotoController'); \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} URL with route name & \$url = route('profile', {[}'id' =\textgreater{} 1{]}); \tn % Row Count 5 (+ 2) % Row 12 \SetRowColor{LightBackground} Generating Redirects... & return redirect()-\textgreater{}route('profile'); \tn % Row Count 7 (+ 2) % Row 13 \SetRowColor{white} Route model binding & Route::get('/users/\{user\}', function (User \$user) \{ return \$user-\textgreater{}email; \}); \tn % Row Count 11 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Controller}} \tn % Row 0 \SetRowColor{LightBackground} Set validation rules & protected \$rules = {[} 'title' =\textgreater{} \seqsplit{'required|unique:posts|max:255'}, 'name' =\textgreater{} 'required|min:6'{]}; \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Validate & \$validatedData = \$request-\textgreater{}validate(\$rules) \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} Show 404 error page & abort(404, 'Sorry, Post not found') \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Artisan common}} \tn % Row 0 \SetRowColor{LightBackground} Database migration & php artisan migrate \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Data seed & php artisan db:seed -{}-class=NomeClasse \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} Create from model & php artisan make:model Product \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} Option for model & -m (migration), -c (controller), -r (resource controllers), -f (factory), -s (seed) \tn % Row Count 9 (+ 4) % Row 4 \SetRowColor{LightBackground} Create a controller & php artisan make:controller ProductsController \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} Update table migration & php artisan make:migration \seqsplit{add\_date\_to\_blogposts\_table} \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} Rollback latest migration & php artisan migrate:rollback \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} Rollback all migrations & php artisan migrate:reset \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} Rollback all and re-migrate & php artisan migrate:refresh \tn % Row Count 21 (+ 2) % Row 9 \SetRowColor{white} Rollback all, re-migrate and seed & php artisan migrate:refresh -{}-seed \tn % Row Count 23 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{HELPERS}} \tn % Row 0 \SetRowColor{LightBackground} Display variable content and kill execution & dd(\$products) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Create a Laravel collection from array. & \$collection = collect(\$array); \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Sort by description ascending & \seqsplit{\$ordered\_collection} = \$collection-\textgreater{}orderBy('description'); \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} Reset numbering value & \seqsplit{\$ordered\_collection} = \$ordered\_collection-\textgreater{}values()-\textgreater{}all(); \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Install a project from github}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{git clone \{project http address\} projectName} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{cd projectName} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{composer install} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{cp .env.example .env} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{php artisan key:generate} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{php artisan migrate} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{npm install} \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Hot reload}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{npm install} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\textasciicircum{}Open webpack.mix.js\textasciicircum{}\{\{nl\}\}mix.browserSync('127.0.0.1:8000')} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{npm install browser-sync \seqsplit{browser-sync-webpack-plugin}} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{php artisan serve} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{npm run watch} \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}