PHP

Laravel Essentials

What is Laravel?

Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern and based on Symfony.

Laravel


Installation

Composer

Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine.

$ composer create-project laravel/laravel your-project-name --prefer-dist

Alternatively, you can install Laravel Installer by running the following command in your terminal:

$ composer global require laravel/installer
$ laravel new <your-project-name>

For macOS, the Laravel installer may have issues with the laravel command not found. To fix this, add the following to your .zshrc file:

$ nano ~/.zshrc

Add the following line to the file:

export PATH="$HOME/.composer/vendor/bin:$PATH"

Herd

Herd is a Laravel client software to allow you to manage your Laravel application environment. You can install all you need including Laravel installer, composer, Nginx, Node.js and multiple PHP versions with just simple clicks.

Download it here


Sanctum

$ php artisan install:api

Configuration


Localization

By default, the Laravel application skeleton does not include the lang directory. If you would like to customize Laravel's language files or create your own, you should scaffold the lang directory via the lang:publish Artisan command. The lang:publish command will create the lang directory in your application and publish the default set of language files used by Laravel:

$ php artisan lang:publish

Logging

Slack Webhook

Laravel provides a convenient way to send log messages to Slack using the Slack webhook.

  1. Create a new channel in your Slack workspace.
  2. Open channel settings and add an app.
  3. Search for "Incoming WebHooks" and add it to your channel.
  4. Configure the webhook settings and select the channel you created.
  5. Copy the webhook URL provided by Slack and add that URL in your .env file:
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/webhook/url

Troubleshooting

failed to listen on 127.0.0.1:8000 (reason ?)

This is happened when you run php artisan serve on Windows. To fix this, open the php.ini file and change variables_order = "EGPCS" to variables_order = "GPCS".

Previous
Drupal