Laravel Valet


Laravel Valet – Laravel Valet is used to provide development environment for Mac minimalists.


Laravel Valet.

Let us understand how to use laravel Valet.

Function:-

There are some followings function available in laravel Valet.

  • 1. Introduction.
  • 2. Installation.
  • 3. Serving Sites.
  • 4. Sharing Sites.
  • 5. Custom Valet Drivers.
  • 6. Other Valet Commands.

1. Introduction.

Valet is a Laravel development environment for Mac minimalists. No Vagrant, no /etc/hosts/ file.

Laravel valet configures your Mac to always run Nginx in the background when your machine starts. Then, using DnsMasq, valet proxies all requests on the *.dev domain to point to sites installed on your local machine.

In other words, a very fast Laravel development environment that uses roughly 7 MB of RAM. Valet isn’t a complete replacement for Vagrant or Homestead, but provides a great alternative if you want flexible basics, prefer extreme speed, or are working on a machine with a limited amount of RAM.

Out of the box, Valet support includes, but is not limited to:

Laravel

Lumen

Symfony

Zend

CakePHP 3

WordPress

Bedrock

Craft

Statamic

Jigsaw

Static Html

However, you may extend Valet with your own Custom Drivers.

Valet Or Homestead

Homestead and Valet both differ in regards to their plan audience and their approach to local development. Homestead offers an entire Ubuntu virtual machine with automated Nginx configuration. Homestead is a wonderful choice if you want a fully virtualized Linux development environment or are on Windows / Linux.

Valet only supports Mac and requires you to install PHP and a database server directly onto your local machine. Valet provides a blazing fast local development environment with minimal resource consumption, so it’s great for developers who only require PHP / MySQL and do not need a fully virtualized development environment.

Both Valet and Homestead are great choices for configuring your Laravel development environment. Which one you choose will depend on your personal taste and your team’s needs.

2. Installation.

Valet requires macOS and Homebrew. Before installation, you should make sure that no other program such as Apache or Nginx are binding to your local machine.
– Install or update Homebrew to the latest version using brew update.
– Install PHP 7.1 using Homebrew via brew install homebrew/php/php7.1.
– Install Valet with composer via Composer global require laravel/valet.
– Run the valet install command. This command will configure and install your valet and DnsMasq and register valet daemon to launvh when your system starts.

Using Another Domain

By default, valet provide your project using the .dev TLD. If you want to use another domain, you can do using the valet domain tld-name command.

Database

If you need a database, to use MYSql by running brew install mysql on your command line. Once MySql has been installed, then you can start it using by brew services start mysql command. Then you can connect to the database at 127.0.0.1 using username is root and password is empty string.

Upgrading

You may update your valet installation using the composer global update command in your terminal.

Upgrading To Valet 2.0

Valet 2.0 transitions Valet’s underlying web server from Caddy to Nginx. Before upgrading to this version you should run the following commands to stop and uninstall the existing Caddy daemon

valet stop
valet uninstall

Now like this you should update to the latest version of valet through composer.

composer global require laravel/valet

Once the fresh valet source code has been downloaded, you should run the install command.

valet install
valet restart

3. Serving Sites.

Once Valet is installed, you are ready to start serving sites. Valet provides two commands to help you serve your Laravel sites which is Park and Link.

The park command.

Create a new directory on your Mac by running something like mkdir ~/Sites. Next,cd ~/Sites and run valet park. This command will register your current working directory as a path that Valet should search for Sites.

Next, create a new laravel site within this directory:laravel new blog.

Open http://blog.dev in your browser.

The link command.

The link command is also used to serve your Laravel site. If you want to serve a single site in a directory and not the entire directory.

To run valet link app-name in your terminal. Valet will create a symbolic link in ~/.valet/Sites which points to your current working directory.

After running the Link command, you can access the site in your browser at http://app-name.dev.

You can use valet unlink app-name to destroy the symbolic link.

4. Sharing Sites.

Valet even includes a command to share your local sites with the world. No additional software installation is required once Valet is installed.

To share a site, navigate to the site’s directory in your terminal and run the valet share command.

To stop sharing your site, hit control + c to cancel the process.

5. Custom Valet Drivers.

You can write your own Valet “driver” to serve PHP applications running on another framework or CMS that is not natively supported by Valet. When you install Valet, a ~/.valet/Drivers directory is created which contains a SampleValetDriver.php file. Writing a driver only requires you to implement three methods serves, isStaticFile and frontControllerPath.

All three methods receive the $sitePath, $siteName and $uri values as their arguments. The $siteName is the fully qualify path to teh site being served on your machine, such as Users/SolidCoupon/Site/My-project. The $siteName is the “Host”/”siteName” portion of the domain {My-project}. The $uri is the incoming request URI (/foo/bar).

The Serves Method

The serve method should return true if your driver should handle the incoming request. Otherwise the method should return false. So, within this method you should attempt to determine if the given $sitePath contains a project of the type you are trying to serve.

public function serves($sitePath, $siteName, $uri)
{
    return is_dir($sitePath.'/wp-admin');
}

The isStaticFile Method

The isStaticFile should determine if the incoming request is for a file that is “static”, such as an image or a stylesheet. If the file is static, the method should return the fully qualified path to the static file on disk. If the incoming request is not for a static file, the method should return false.

public function isStaticFile($sitePath, $siteName, $uri)
{
    if (file_exists($staticFilePath = $sitePath.'/public/'.$uri)) {
        return $staticFilePath;
    }

    return false;
}

The frontControllerPath Method

The frontControllerPath method should return the fully qualified path to your application’s “front controller”, which is typically your “index.php” file or equivalent.

public function frontControllerPath($sitePath, $siteName, $uri)
{
    return $sitePath.'/public/index.php';
}

6. Other Valet Commands.

Laravel Valet

Advertisements

Add Comment

đź“– Read More