Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Beautiful PHP CLI Menus for Laravel Artisan Commands
Feb 05, 2018 @ 16:33:53

On the Laravel News site today there's a post that highlights a package that makes it easier to create beautiful CLI menus for artisan commands in the Laravel framework.

Nuno Maduro, author of Laravel Zero and Collision (which nunomaduro/laravel-console-menu.

The post includes an example of code that can create the menu and its options. It also shows how you can change the look of the default menu, changing colors, the "selected" marker, padding and width. The package makes use of the php-school/cli-menu package for a lot of the base menu rendering and functionality.

tagged: tutorial menu cli artisan command laravel package

Link: https://laravel-news.com/beautiful-php-cli-menus-laravel-artisan-commands

Sarfraz Ahmed:
Laravel: Automatic Vendor Cleanup Command
Jan 25, 2018 @ 15:42:47

In a post to his site Sarfraz Ahmed shares a command that can be used in a Laravel application (via artisan) to clean up unnecessary files from packages that you may have installed.

When installing composer packages, they come up with lot of useless files and folders such as .git, tests, readme.md and more. When project becomes bigger with many packages, this junk takes considerable disk space. Since I work with Laravel framework most of the time, I created a command that allows me to automatically delete all these junk files whenever I happen to install or update composer packages.

He lists out the patterns the command matches by default including "tests", "readme*" and "*.log". There's a long list of items and, having worked with several packages, I can tell you that most of the files caught by this need to be removed anyway. He has posted the code on GitHub and provides some examples of the command line calls and how it can be called automatically.

Another package that does something similar but allows the package itself to define the files to remove is the composerclean library that is executed as a Composer command rather than an artisan command.

tagged: composer laravel automatic clean method artisan

Link: http://codeinphp.github.io/post/laravel-automatic-vendor-cleanup-command/

TutsPlus.com:
Task Scheduling in Laravel
Dec 04, 2017 @ 16:51:52

On the TutsPlus.com site there's a new tutorial posted introducing you to task scheduling in Laravel, a feature that allows you to run code in the application periodically similar to a cron job.

In this article, we’ll go through one of the exciting features of the Laravel web framework—task scheduling. Throughout the course of this article, we’ll look at how Laravel allows you to manage scheduled tasks in your application. Moreover, we’ll also end up creating our own custom scheduled tasks for demonstration purposes.

The Laravel framework allows you to set up scheduled tasks so that you don't have to worry about setting them up at the system level. You can get rid of that complex cron syntax while setting up scheduled tasks since Laravel allows you to define them in a user-friendly way.

The article starts with a brief introduction to cron jobs, how they're set up and some issues that come along with them. Next the article describes the "Laravel Way" of handling task scheduling, showing how to use Laravel's artisan command to run the scheduler. With the basics laid out, the author then walks through how to create a custom task either using a closure/callable, making an artisan command or using the exec command. Code examples are included for each and more information about scheduling options and functionality can be found in the Laravel manual.

tagged: task schedule tutorial laravel artisan closure exec command

Link: https://code.tutsplus.com/tutorials/tasks-scheduling-in-laravel--cms-29815

Laravel News:
Laravel 5.6 Will Remove the Artisan Optimize Command
Sep 22, 2017 @ 15:23:13

As this post to Laravel News mentions the upcoming v5.6 release of the framework will remove the artisan optimize functionality from the project's artisan command line tool.

The Artisan optimize command is deprecated as of 5.5, and a commit in master has already removed it from 5.6. Waiting until 5.6 gives you time to update your build scripts and composer.json files ahead of the release.

As of Laravel 5.5, the composer.json no longer references optimize in the post-install-cmd and post-update-cmd scripts. The Optimize command is still defined, but does nothing in 5.5.

The project has provided some reasoning behind the change, mostly having to do with the overall performance improvements in the PHP language itself. Additionally, there was some discussion around the removal before it was finalized.

tagged: laravel optimize command removed v56 framework commandline artisan

Link: https://laravel-news.com/laravel-5-6-removes-artisan-optimize

Laravel News:
Getting to Know the Laravel Tinker Shell
Sep 12, 2017 @ 16:30:39

On the Laravel News site today there's a post introducing you to Tinker the command-line REPL (read-eval-print-loop) tool that integrates with the Laravel artisan command-line tool.

Laravel includes a powerful REPL, called Tinker, powered by the PsySH console by Justin Hileman under the hood. The tinker console allows you to interact with your Laravel application from the command line in an interactive shell.

Tinker used to be part of the laravel/framework package, but with the release of Laravel 5.4 is extracted into separate package.

They start the post by talking about what a REPL is and how it can be used to test things on the command line without needing to write up a full test script. They then show how to install the tool Tinker is based on globally (Psych) including a brief overview of how to use it. Next comes the Tinker-specific functionality including examples of the documentation commands, testing helpers and job execution features.

tagged: tinker artisan shell repl psych tutorial introduction

Link: https://laravel-news.com/laravel-tinker

php[architect]:
Artisanal: Project Creation
May 18, 2017 @ 16:59:12

On the php[architect] site they've shared an article originally from the May 2016 issue of the magazine by Joe Ferguson: Artisanal: Project Creation (also released as a free PDF).

Every developer has a set way of starting a new project. Most frameworks have a linear path to getting started, and Laravel is no exception. With a few commands, you can quickly get started configuring routes, writing controllers, and saving data in a database.

In the article Joe walks you through the tools and commands that come with the Laravel framework to make getting up and running quickly easier. He covers tools available for both the backend and frontend functionality as well as testing (mentioning Dusk), routing, middleware groups and database functionality.

tagged: phparchitect magazine free article project creation laravel artisan

Link: https://www.phparch.com/2017/05/artisanal-project-creation/

Tighten.co:
Supercharge Your Laravel Tinker Workflow
May 11, 2017 @ 14:37:19

On the Tighten.co blog they have a new post that aims to help you get the most out of the Laravel command line tool's (artisan) tinker command.

Laravel's command line tool is called "Artisan," and it comes with a few powerful features out of the box. Tinker, accessed via php artisan tinker, is arguably my favorite Artisan command. It speeds up my workflow and allows me to interact with my application in ways I would have never thought possible.

Tinker is a REPL (read-eval-print loop). A REPL gives you a prompt that allows you to interact with your application using your language's native syntax (in this case, PHP) in a command-line style.

The post then walks through some of the "hidden features" this command line tool offers including:

  • basic usage to call Laravel code (like getting all posts using Post::all)
  • a more interactive version of dd(), a debugging tool
  • improving speed on a Laravel Dusk testing workflow
  • direct access to the PHP docs

The post ends with a few other smaller things this helpful tool can do like showing a stack trace, listing the command history and re-throwing the last exception.

tagged: laravel workflow tinker commandline tool artisan tutorial

Link: https://blog.tighten.co/supercharge-your-laravel-tinker-workflow

Matt Stauffer:
Creating Artisan commands with the new, simpler syntax in Laravel 5.1
Jun 11, 2015 @ 15:27:56

Matt Stauffer has posted the latest in his "What's New in Laravel 5" series today with a look at the changes in creating Artisan commands with a newer, simpler syntax.

If you're not familiar with Artisan commands, they're command-line functions that you can run to interact with your Laravel application. If you run php artisan from the command line in any Laravel application directory, you'll see a list of all of the Artisan commands available for each app. As you can see, Laravel comes with quite a few enabled out of the box.

He starts with a look at the old way of creating the commands using the "artisan make:console" command to build the class and an example of its contents. This version requires a good bit of extra code to reference things like arguments and define required parameters. He then compares this with the new way with a much simpler syntax and reduced about of code overall. One of the main differences he mentions is the concept of a "signature" for the command - a specially formatted string that defines configuration such as required and optional parameters. He finishes the post with a few examples of these signatures.

tagged: artisan commands syntax create laravel5 tutorial

Link: https://mattstauffer.co/blog/creating-artisan-commands-with-the-new-simpler-syntax-in-laravel-5.1

Mike Bronner:
Run #AllTheCommands Outside of Homestead
Mar 04, 2015 @ 16:02:49

In this new post Mike Bronner shows you how to get the latest PHP5 and Mcrypt versions installed on OS X Yosemite to make ti easier on developers needing to run commands outside of Homestead.

Laravel Homestead has brought virtual machines for web development to the mainstream PHP developer: it makes setting up a development stack similar to XAMP extremely simple. [...] However, one of the drawbacks so far has been that you always needed to run Laravel Artisan commands from within homestead, as they depending on MCrypt being installed. [...] The accepted solution thus far has been to install newer versions of PHP alongside Apple’s version using Homebrew or MacPorts. [...] However, there’s another method I came across while research some non-related issues: install the latest version of PHP from a binary that includes the MCrypt extension.

He walks you through the complete process (well, except for getting Homestead - that needs to already be there) complete with each command you'll need. You'll need to be familiar with the command line to make this all happen and know how to edit configuration files. If all goes well, the "artisan" command will work correctly and no errors will happen during the compile. He also includes a fix you'll need to put in to get the database configuration working from outside Homestead too.

tagged: laravel homestead command artisan mcrypt install configure database

Link: https://medium.com/@genealabs/run-allthecommands-outside-of-homestead-e2fc8d05251f

SitePoint PHP Blog:
How to Create a Laravel CSS-Minify Command
Jun 11, 2014 @ 19:58:31

The SitePoint PHP blog has a new post today from Tounes Rafie showing you how, in a Laravel framework based application, to create a minify command with the framework's "artisan" command.

In this article you’ll learn how to use Laravel’s Artisan command line tool, and how to create a customized command. Note that you need to be familiar with the Laravel framework to get the most of this article. In this tutorial we’re going to build a command to minify our css assets.

He starts with a (very) brief look at what Laravel commands are and the options this articular one will include. Next up is the code you'll need to create the command, making use of Laravel's integration of the Symfony Console component. He shows how to register the command with the rest of the application and how to work with the options/arguments for the input. From there he shows how to run the command and how to make some other improvements including colorized output and more information on execution.

tagged: css minify command laravel artisan framework tutorial

Link: http://www.sitepoint.com/create-laravel-css-minify-command


Trending Topics: