### Install Laravel Installer Globally Source: https://laravel.com/docs/4.2/docs/4.2/quick Installs the Laravel installer tool globally via Composer, enabling quick creation of new Laravel projects. Ensure Composer's global vendor bin directory is in your system's PATH. ```bash composer global require "laravel/installer=~1.1" ``` -------------------------------- ### Manage Laravel Dependencies with Composer Source: https://laravel.com/docs/4.2/docs/4 After downloading Laravel, use these Composer commands to install or update the framework's dependencies. Git must be installed on the server for this process. ```bash php composer.phar install # or composer install ``` ```bash php composer.phar update ``` -------------------------------- ### Install Laravel Installer Globally via Composer Source: https://laravel.com/docs/4.2/docs/4 This command installs the Laravel installer globally using Composer, enabling faster project creation with the `laravel new` command. Ensure the Composer vendor bin directory is in your system's PATH. ```bash composer global require "laravel/installer=~1.1" ``` -------------------------------- ### Serve Laravel Application on a Custom Port Source: https://laravel.com/docs/4.2/docs/4.2/quick Starts the Laravel development server on a specified port using the `--port` argument. Useful when port 8000 is occupied or for running multiple applications concurrently. ```bash php artisan serve --port=8080 ``` -------------------------------- ### Serve Laravel Application with PHP's Built-in Server Source: https://laravel.com/docs/4.2/docs/4.2/quick Starts a development server for your Laravel application using PHP's built-in server, listening on port 8000 by default. This is convenient for local development. ```bash php artisan serve ``` -------------------------------- ### Install and Update Laravel Dependencies via Composer Source: https://laravel.com/docs/4.2/docs/4.2/installation After downloading the Laravel framework, these commands are used to install or update its dependencies using Composer. The 'install' command sets up the project's vendor directory, while 'update' refreshes existing dependencies. Note that Git must be installed on the server for this process to complete successfully. ```bash php composer.phar install ``` ```bash composer install ``` ```bash php composer.phar update ``` -------------------------------- ### Example Controller Action Using Laravel Facade Source: https://laravel.com/docs/4.2/docs/4.2/testing This code provides a simple Laravel controller action that demonstrates the use of a static facade, `Event::fire`, to trigger an event. This serves as a foundational example for understanding how facades are typically used in Laravel applications, which is then relevant for mocking them in tests. ```PHP public function getIndex() { Event::fire('foo', array('name' => 'Dayle')); return 'All done!'; } ``` -------------------------------- ### Create New Laravel 4.2 Project via Composer Source: https://laravel.com/docs/4.2/docs/4.2/quick Downloads and installs a fresh Laravel 4.2 application into a new directory using Composer. Replace `your-project-name` with the desired project folder name. ```bash composer create-project laravel/laravel your-project-name 4.2.* ``` -------------------------------- ### Install Laravel Installer Globally via Composer Source: https://laravel.com/docs/4.2/docs/4.2/installation This command installs the Laravel Installer globally using Composer, making the 'laravel' command available system-wide for quickly creating new Laravel projects. Ensure your Composer vendor bin directory (~/.composer/vendor/bin) is added to your system's PATH environment variable for the command to be found. ```bash composer global require "laravel/installer=~1.1" ``` -------------------------------- ### Create New Laravel 4.2 Project with Composer Source: https://laravel.com/docs/4.2/docs/4 Use this Composer command to create a fresh Laravel 4.2 project in a specified directory. This method installs all necessary dependencies directly. ```bash composer create-project laravel/laravel {directory} 4.2 --prefer-dist ``` -------------------------------- ### Create New Laravel 4.2 Project via Composer Source: https://laravel.com/docs/4.2/docs/4.2/installation This Composer command creates a fresh Laravel 4.2 project in the specified directory, downloading all necessary dependencies. It's an alternative to using the Laravel Installer for setting up a new application, directly leveraging Composer's project creation capabilities. ```bash composer create-project laravel/laravel {directory} 4.2 --prefer-dist ``` -------------------------------- ### Define a Basic Laravel 4.2 Closure Route Source: https://laravel.com/docs/4.2/docs/4.2/quick Illustrates how to define a simple GET route in `app/routes.php` that maps a URL to an anonymous function, returning a direct response. This is the simplest form of routing. ```php Route::get('users', function() { return 'Users!'; }); ``` -------------------------------- ### Call Laravel Routes from Tests Source: https://laravel.com/docs/4.2/docs/4.2/testing This example shows how to simulate HTTP requests to Laravel routes within a test using the `call` method. It demonstrates both a simple GET request and a more complex call with various parameters, returning an `Illuminate\Http\Response` object for further inspection. ```PHP $response = $this->call('GET', 'user/profile'); $response = $this->call($method, $uri, $parameters, $files, $server, $content); ``` -------------------------------- ### Install Laravel Homestead Manually via Git Source: https://laravel.com/docs/4.2/docs/4.2/homestead Clones the Laravel Homestead repository from GitHub. This method is an alternative to Composer installation, especially useful if PHP is not installed locally. It's recommended to clone it into a central directory for all Laravel projects. ```Bash git clone https://github.com/laravel/homestead.git Homestead ``` -------------------------------- ### Define a Laravel 4.2 Route to a Controller Action Source: https://laravel.com/docs/4.2/docs/4.2/quick Shows how to map a URL to a specific method within a controller class. This approach promotes better organization and separation of concerns in Laravel applications. ```php Route::get('users', 'UserController@getIndex'); ``` -------------------------------- ### Example Laravel Database Seeder Classes Source: https://laravel.com/docs/4.2/docs/4.2/migrations Provides example PHP classes for seeding a Laravel database. It illustrates how to define a `DatabaseSeeder` to call other seeder classes and a `UserTableSeeder` to insert sample user data into the `users` table. ```php class DatabaseSeeder extends Seeder { public function run() { $this->call('UserTableSeeder'); $this->command->info('User table seeded!'); } } class UserTableSeeder extends Seeder { public function run() { DB::table('users')->delete(); User::create(array('email' => 'example@example.com')); } } ``` -------------------------------- ### Define a Laravel Route to Return a Blade View Source: https://laravel.com/docs/4.2/docs/4.2/quick This PHP snippet demonstrates how to configure a Laravel route (`/users`) to render and return a Blade view instead of a simple string. It uses `View::make('users')` to instantiate and display the `users.blade.php` template. ```PHP Route::get('users', function() { return View::make('users'); }); ``` -------------------------------- ### Install Laravel Homestead CLI Tool via Composer Source: https://laravel.com/docs/4.2/docs/4.2/homestead Installs the Homestead command-line interface (CLI) tool globally using Composer. This allows for easy management of Homestead environments. Ensure Composer's global bin directory (~/.composer/vendor/bin) is in your system's PATH. ```Bash composer global require "laravel/homestead=~2.0" ``` -------------------------------- ### Declare Variables and Run PHP with Envoy @setup Source: https://laravel.com/docs/4.2/docs/4.2/ssh Explains how to use the `@setup` directive in an Envoy file to declare PHP variables and perform initial setup logic before tasks are executed. ```Envoy Blade @setup $now = new DateTime(); $environment = isset($env) ? $env : "testing"; @endsetup ``` -------------------------------- ### Install Laravel Envoy Globally Source: https://laravel.com/docs/4.2/docs/4.2/ssh Instructions for installing Laravel Envoy globally via Composer. This command makes the `envoy` executable available system-wide for defining and running remote tasks. ```Bash composer global require "laravel/envoy=~1.0" ``` -------------------------------- ### Manage Session State in Laravel Tests Source: https://laravel.com/docs/4.2/docs/4.2/testing Provides examples of setting session data and flushing the session entirely within Laravel tests. ```PHP $this->session(['foo' => 'bar']); $this->flushSession(); ``` -------------------------------- ### Get Application Root Path (base_path) Source: https://laravel.com/docs/4.2/docs/4.2/helpers Get the fully qualified path to the root of the application install. ```APIDOC base_path() ``` -------------------------------- ### Execute Pending Database Migrations with Artisan Source: https://laravel.com/docs/4.2/docs/4.2/quick This command-line snippet runs all pending database migrations. Executing `php artisan migrate` applies the schema changes defined in the `up` methods of all new migration files to the configured database, updating its structure. ```Bash php artisan migrate ``` -------------------------------- ### Define a Basic Laravel View Source: https://laravel.com/docs/4.2/docs/4.2/responses Provides an example of a simple HTML view file (`greeting.php`) stored in `app/views`, demonstrating how to display a PHP variable. ```HTML
{{ $user->name }}
@endforeach @stop ``` -------------------------------- ### SSH (Instance) Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel SSH (Instance) Facade, including its underlying class and IoC binding. ```APIDOC Facade: SSH (Instance) Class: Illuminate\Remote\Connection IoC Binding: ``` -------------------------------- ### File Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel File Facade, including its underlying class and IoC binding. ```APIDOC Facade: File Class: Illuminate\Filesystem\Filesystem IoC Binding: files ``` -------------------------------- ### Run a Basic Envoy Task Source: https://laravel.com/docs/4.2/docs/4.2/ssh Demonstrates how to execute a simple task defined in an Envoy file using the `envoy run` command. ```Bash envoy run foo ``` -------------------------------- ### Update Global Composer Packages (including Envoy) Source: https://laravel.com/docs/4.2/docs/4.2/ssh Shows how to update globally installed Composer packages, which can include Envoy if it was installed via Composer's global installer. ```Bash composer global update ``` -------------------------------- ### Route to a Namespaced Laravel Controller Action Source: https://laravel.com/docs/4.2/docs/4.2/controllers When controllers are organized using PHP namespaces, this example shows how to specify the fully qualified class name in the route definition. This ensures Laravel correctly locates the controller and its method. ```PHP Route::get('foo', 'Namespace\FooController@method'); ``` -------------------------------- ### Perform a Basic Redirect Source: https://laravel.com/docs/4.2/docs/4.2/responses Shows how to redirect the user to a specified URL using the `Redirect::to` method. ```PHP return Redirect::to('user/login'); ``` -------------------------------- ### App Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel App Facade, including its underlying class and IoC binding. ```APIDOC Facade: App Class: Illuminate\Foundation\Application IoC Binding: app ``` -------------------------------- ### Get Public Directory Path (public_path) Source: https://laravel.com/docs/4.2/docs/4.2/helpers Get the fully qualified path to the `public` directory. ```APIDOC public_path() ``` -------------------------------- ### Accessing Laravel 4.1 Full Change List Source: https://laravel.com/docs/4.2/docs/4.2/releases The complete list of changes for Laravel 4.1 can be viewed by running the `php artisan changes` command from a 4.1 installation. This provides a detailed overview of all enhancements and modifications. ```Bash php artisan changes ``` -------------------------------- ### Update Envoy Installation via self-update Command Source: https://laravel.com/docs/4.2/docs/4.2/ssh Provides the command to update the Envoy installation directly using its built-in `self-update` feature. ```Bash envoy self-update ``` -------------------------------- ### Queue Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Queue Facade, including its underlying class and IoC binding. ```APIDOC Facade: Queue Class: Illuminate\Queue\QueueManager IoC Binding: queue ``` -------------------------------- ### Get All Request Input in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests This code demonstrates how to retrieve all user input submitted with the current request as an associative array. This includes data from GET, POST, and other request methods. ```PHP $input = Input::all(); ``` -------------------------------- ### Subscribe User to a Plan with a Coupon Source: https://laravel.com/docs/4.2/docs/4.2/billing This snippet shows how to apply a coupon code when creating a new subscription by chaining the `withCoupon` method before calling `create`. ```PHP $user->subscription('monthly') ->withCoupon('code') ->create($creditCardToken); ``` -------------------------------- ### Log Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Log Facade, including its underlying class and IoC binding. ```APIDOC Facade: Log Class: Illuminate\Log\Writer IoC Binding: log ``` -------------------------------- ### Starting Laravel Daemon Queue Worker Source: https://laravel.com/docs/4.2/docs/4.2/queues Initiates a queue worker in daemon mode, allowing it to continuously process jobs without re-booting the framework, which significantly reduces CPU usage. This mode requires careful handling during deployments to drain existing jobs. ```PHP php artisan queue:work connection --daemon php artisan queue:work connection --daemon --sleep=3 php artisan queue:work connection --daemon --sleep=3 --tries=3 ``` -------------------------------- ### Implementing the Cache Store Interface for a Custom Driver Source: https://laravel.com/docs/4.2/docs/4.2/extending Defines the `MongoStore` class, which implements the `Illuminate\Cache\StoreInterface`. This interface requires specific methods like `get`, `put`, `increment`, `decrement`, `forever`, `forget`, and `flush` to be implemented for a custom cache driver to function correctly. ```PHP class MongoStore implements Illuminate\Cache\StoreInterface { public function get($key) {} public function put($key, $value, $minutes) {} public function increment($key, $value = 1) {} public function decrement($key, $value = 1) {} public function forever($key, $value) {} public function forget($key) {} public function flush() {} } ``` -------------------------------- ### Download Files and Strings via SFTP Source: https://laravel.com/docs/4.2/docs/4.2/ssh Shows how to download files from a remote server to a local path using `get` and retrieve file contents directly as a string using `getString` via SFTP. Both methods operate on a specified SSH connection. ```PHP SSH::into('staging')->get($remotePath, $localPath); $contents = SSH::into('staging')->getString($remotePath); ``` -------------------------------- ### Instantiate Laravel Application Core Source: https://laravel.com/docs/4.2/docs/4.2/extending This snippet shows the foundational line of code that instantiates the Laravel application. This `Application` instance is responsible for bootstrapping the framework, including binding the default `Illuminate\Http\Request` instance to the IoC container. Understanding this step is crucial for customizing core components like the Request class. ```PHP $app = new \Illuminate\Foundation\Application; ``` -------------------------------- ### Queue (Base Class) Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Queue (Base Class) Facade, including its underlying class and IoC binding. ```APIDOC Facade: Queue (Base Class) Class: Illuminate\Queue\Queue IoC Binding: ``` -------------------------------- ### Retrieve Request URI in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests Demonstrates how to get the URI of the current request using `Request::path()`. ```PHP $uri = Request::path(); ``` -------------------------------- ### Initialize Homestead Configuration File Source: https://laravel.com/docs/4.2/docs/4.2/homestead Generates the 'Homestead.yaml' configuration file in the '~/.homestead' directory. This file is used to customize your Homestead environment settings, such as shared folders and SSH keys. ```Bash homestead init ``` -------------------------------- ### Laravel Validation Rule: confirmed Source: https://laravel.com/docs/4.2/docs/4.2/validation Ensures a field has a matching `_confirmation` field. For example, `password` requires `password_confirmation`. ```APIDOC confirmed: Description: The field under validation must have a matching field of `foo_confirmation`. Example: If the field is `password`, `password_confirmation` must be present in the input. ``` -------------------------------- ### Running Laravel Database Migrations Source: https://laravel.com/docs/4.2/docs/4.2/migrations Explains how to execute pending database migrations using the `php artisan migrate` command. It covers running all outstanding migrations, migrations for a specific path or package, and forcing destructive operations in production environments. ```php php artisan migrate ``` ```php php artisan migrate --path=app/foo/migrations ``` ```php php artisan migrate --package=vendor/package ``` ```php php artisan migrate --force ``` -------------------------------- ### Retrieve Uploaded File Size in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests Explains how to get the size of an uploaded file in bytes using `getSize()`. ```PHP $size = Input::file('photo')->getSize(); ``` -------------------------------- ### Retrieve Uploaded File MIME Type in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests Shows how to get the MIME type of an uploaded file using `getMimeType()`. ```PHP $mime = Input::file('photo')->getMimeType(); ``` -------------------------------- ### Config Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Config Facade, including its underlying class and IoC binding. ```APIDOC Facade: Config Class: Illuminate\Config\Repository IoC Binding: config ``` -------------------------------- ### Retrieve Uploaded File Extension in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests Demonstrates how to get the original file extension of an uploaded file using `getClientOriginalExtension()`. ```PHP $extension = Input::file('photo')->getClientOriginalExtension(); ``` -------------------------------- ### URL Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel URL Facade, including its underlying class and IoC binding. ```APIDOC Facade: URL Class: Illuminate\Routing\UrlGenerator IoC Binding: url ``` -------------------------------- ### Retrieve an Uploaded File in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests Explains how to get an instance of the `UploadedFile` class for an uploaded file using `Input::file()`. ```PHP $file = Input::file('photo'); ``` -------------------------------- ### HTML Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel HTML Facade, including its underlying class and IoC binding. ```APIDOC Facade: HTML Class: Illuminate\Html\HtmlBuilder IoC Binding: html ``` -------------------------------- ### Log Out User in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/security Logs the currently authenticated user out of the application, clearing their session and authentication state. ```PHP Auth::logout(); ``` -------------------------------- ### Auth Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Auth Facade, including its underlying class and IoC binding. ```APIDOC Facade: Auth Class: Illuminate\Auth\AuthManager IoC Binding: auth ``` -------------------------------- ### Retrieve Original Uploaded File Name in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests Shows how to get the original filename as it was on the client's machine using `getClientOriginalName()`. ```PHP $name = Input::file('photo')->getClientOriginalName(); ``` -------------------------------- ### Calling Laravel Cache Facade Source: https://laravel.com/docs/4.2/docs/4.2/facades This snippet demonstrates a typical call to a Laravel facade, which appears to be a static method call on the `Cache` class. ```PHP $value = Cache::get('key'); ``` -------------------------------- ### Update BaseController Use Statement in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/upgrade Change the `use` statement in `app/controllers/BaseController.php` to reflect the updated namespace for `Controller`. ```PHP // Before: use Illuminate\Routing\Controllers\Controller; // After: use Illuminate\Routing\Controller; ``` -------------------------------- ### Configure Nginx Sites in Homestead.yaml Source: https://laravel.com/docs/4.2/docs/4.2/homestead This configuration snippet demonstrates how to map a domain to a public directory within your Homestead environment using the `sites` property. It also shows how to enable HHVM for a specific site, allowing for flexible web server configurations. ```YAML sites: - map: homestead.app to: /home/vagrant/Code/Laravel/public hhvm: true ``` -------------------------------- ### Retrieve Uploaded File Path in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests Explains how to get the absolute path to an uploaded file's temporary location using `getRealPath()`. ```PHP $path = Input::file('photo')->getRealPath(); ``` -------------------------------- ### Check if String Starts With (starts_with) Source: https://laravel.com/docs/4.2/docs/4.2/helpers The `starts_with` function determines if a given string (haystack) begins with a specified substring (needle). ```PHP $value = starts_with('This is my name', 'This'); ``` -------------------------------- ### Access Current Route in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/upgrade The method for accessing the current route has changed. Use `Route::current()` instead of `Route::getCurrentRoute()`. ```PHP // Before: Route::getCurrentRoute(); // After: Route::current(); ``` -------------------------------- ### Mock Laravel Facades for Testing with Mockery Source: https://laravel.com/docs/4.2/docs/4.2/testing This snippet illustrates how to mock a Laravel static facade, such as `Event`, using Mockery's `shouldReceive` method. This allows you to test interactions with facades without their actual execution, ensuring specific methods are called with expected arguments and controlling their return values. ```PHP public function testGetIndex() { Event::shouldReceive('fire')->once()->with('foo', array('name' => 'Dayle')); $this->call('GET', '/'); } ``` -------------------------------- ### Get All Error Messages for a Field in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/validation Illustrates how to retrieve and iterate through all validation error messages for a specific field. This is useful when a field might have multiple validation failures. ```PHP foreach ($messages->get('email') as $message) { // } ``` -------------------------------- ### DB Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel DB Facade, including its underlying class and IoC binding. ```APIDOC Facade: DB Class: Illuminate\Database\DatabaseManager IoC Binding: db ``` -------------------------------- ### Hash Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Hash Facade, including its underlying class and IoC binding. ```APIDOC Facade: Hash Class: Illuminate\Hashing\HasherInterface IoC Binding: hash ``` -------------------------------- ### Artisan Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Artisan Facade, including its underlying class and IoC binding. ```APIDOC Facade: Artisan Class: Illuminate\Console\Application IoC Binding: artisan ``` -------------------------------- ### Set Authenticated User in Laravel Tests Source: https://laravel.com/docs/4.2/docs/4.2/testing Explains how to set a user as currently authenticated for the duration of a test using the `be` method in Laravel. ```PHP $user = new User(array('name' => 'John')); $this->be($user); ``` -------------------------------- ### Log In User by ID in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/security Authenticates a user directly using their user ID without requiring credentials, useful for programmatic login. ```PHP Auth::loginUsingId(1); ``` -------------------------------- ### Schema Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Schema Facade, including its underlying class and IoC binding. ```APIDOC Facade: Schema Class: Illuminate\Database\Schema\Blueprint IoC Binding: ``` -------------------------------- ### Get All Error Messages for All Fields in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/validation Demonstrates how to retrieve and iterate through all validation error messages across all fields. This is commonly used to display a comprehensive list of errors to the user. ```PHP foreach ($messages->all() as $message) { // } ``` -------------------------------- ### Get The Request URL in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/requests Retrieves the full URL for the current request using `Request::url()`. This includes the scheme, host, and path, but excludes the query string. ```PHP $url = Request::url(); ``` -------------------------------- ### Response Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Response Facade, including its underlying class and IoC binding. ```APIDOC Facade: Response Class: Illuminate\Support\Facades\Response IoC Binding: ``` -------------------------------- ### Get Class Basename (class_basename) Source: https://laravel.com/docs/4.2/docs/4.2/helpers The `class_basename` function extracts the class name from a fully qualified class name string, removing any namespace prefixes. ```PHP $class = class_basename('Foo\Bar\Baz'); // Baz ``` -------------------------------- ### Route Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Route Facade, including its underlying class and IoC binding. ```APIDOC Facade: Route Class: Illuminate\Routing\Router IoC Binding: router ``` -------------------------------- ### Running Laravel Database Seeders Source: https://laravel.com/docs/4.2/docs/4.2/migrations Explains how to execute database seeders using Artisan commands. It covers running the default `DatabaseSeeder` or a specific seeder class, and notes the option to run seeders after a `migrate:refresh` operation. ```php php artisan db:seed ``` ```php php artisan db:seed --class=UserTableSeeder ``` ```php php artisan migrate:refresh --seed ``` -------------------------------- ### Execute General SQL Statements with Laravel DB Facade Source: https://laravel.com/docs/4.2/docs/4.2/database This snippet demonstrates how to run any general SQL statement, such as DDL commands (e.g., `DROP TABLE`), using Laravel's `DB::statement` method. It takes a raw SQL string as input. ```PHP DB::statement('drop table users'); ``` -------------------------------- ### Session Facade Reference Source: https://laravel.com/docs/4.2/docs/4.2/facades Details for the Laravel Session Facade, including its underlying class and IoC binding. ```APIDOC Facade: Session Class: Illuminate\Session\SessionManager IoC Binding: session ``` -------------------------------- ### Add Homestead Domain to Local Hosts File Source: https://laravel.com/docs/4.2/docs/4.2/homestead This example shows the format for adding an entry to your local machine's `hosts` file. This entry redirects requests for your configured Homestead domain (e.g., `homestead.app`) to the IP address of your Homestead virtual machine, enabling local access. ```Hosts File 192.168.10.10 homestead.app ``` -------------------------------- ### Assert Old Input Data in Laravel Tests Source: https://laravel.com/docs/4.2/docs/4.2/testing Shows how to assert that old input data is present in the session after a request in Laravel tests. ```PHP public function testMethod() { $this->call('GET', '/'); $this->assertHasOldInput(); } ``` -------------------------------- ### Protect Route with 'auth' Filter in Laravel Source: https://laravel.com/docs/4.2/docs/4.2/security Applies the default 'auth' filter to a route, restricting access to only authenticated users. The filter is defined in `app/filters.php`. ```PHP Route::get('profile', array('before' => 'auth', function() { // Only authenticated users may enter... })); ``` -------------------------------- ### Execute SELECT Queries with Laravel DB Facade Source: https://laravel.com/docs/4.2/docs/4.2/database This snippet shows how to perform a SELECT query using Laravel's `DB::select` method. It demonstrates passing a raw SQL query with a placeholder and an array of bindings. The method will always return an array of results. ```PHP $results = DB::select('select * from users where id = ?', array(1)); ```