This draft deletes the entire topic.
Examples
-
Laravel applications are installed and managed with Composer, a popular PHP dependency manager. There are two ways to create a new Laravel application.
Via Composer
$ composer create-project laravel/laravel [foldername]
Replace [foldername] with the name of the directory you want your new Laravel application installed to. It must not exist before installation. You may also need to add the Composer executable to your system path.
Via the Laravel installer
Laravel provides a helpful command line utility to quickly create Laravel applications. First, install the installer:
$ composer global require laravel/installer
You have to make sure that the Composer binaries folder is within your $PATH variable to execute the Laravel installer.
First, look if it already is in your $PATH variable
echo $PATH
If everything is correct, the output should contain something like this:
Users/yourusername/.composer/vendor/bin
If not, edit your
.bashrc
or, if your using ZSH, your.zshrc
so it contains the path to your Composer vendor directory.Once installed, this command will create a fresh Laravel installation in the directory you specify.
laravel new [foldername]
You can also use
.
(a dot) in place of [foldername] to create the project in the current working directory without making a sub-directory.Running the application
Laravel comes bundled with a PHP-based web server which can be started by running
$ php artisan serve
By default the HTTP server will use port 8000, but if the port is already in use or if you want to run multiple Laravel applications at once, you can use the
--port
flag to specify a different port:$ php artisan serve --port=8080
Using a different server
If you prefer to use a different web server software, some configuration files are provided for you inside the
public
directory of your project;.htaccess
for Apache andweb.config
for ASP.NET. For other software such as Nginx, you can convert the Apache configurations using various online tools.
The framework needs the web server user to have write permissions on the following directories:
/storage
/bootstrap/cache
On *nix operating systems this can be achieved by
chgrp -R www-data:www-data storage bootstrap/cache chmod -R ug+rwx storage bootstrap/cache
(where "www-data" is the name (and group) of the web server user)
The web server of your choice should be configured to serve content from your project's
/public
directory, which is usually done by setting it as the document root. The rest of your project should not be accessible through your web server.If you set everything up properly, navigating to your website's URL should display the default landing page of Laravel.
-
The Laravel framework has the following requirements:
5.3- PHP >= 5.6.4
- XML PHP Extension
- PDO PHP Extension
5.1 (LTS)5.2- PHP >= 5.5.9
- PDO PHP Extension
- Laravel 5.1 is the first version of Laravel to support PHP 7.0.
5.0- PHP >= 5.4, PHP < 7
- OpenSSL PHP Extension
- Tokenizer PHP Extension
- Mbstring PHP Extension
- JSON PHP extension (only on PHP 5.5)
4.2- PHP >= 5.4
- Mbstring PHP Extension
- JSON PHP extension (only on PHP 5.5)
-
-
LaraDock is a Laravel Homestead like development environment but for Docker instead of Vagrant. https://github.com/LaraDock/laradock
Installation
*Requires Git and Docker
Clone the LaraDock repository:
A. If you already have a Laravel project, clone this repository on your Laravel root directory:
git submodule add https://github.com/LaraDock/laradock.git
B. If you don't have a Laravel project, and you want to install Laravel from Docker, clone this repo anywhere on your machine:
git clone https://github.com/LaraDock/laradock.git
Basic Usage
-
Run Containers: (Make sure you are in the laradock folder before running the docker-compose commands).
Example: Running NGINX and MySQL:
docker-compose up -d nginx mysql
There are a list of available containers you can select to create your own combinations.
nginx
,hhvm
,php-fpm
,mysql
,redis
,postgres
,mariadb
,neo4j
,mongo
,apache2
,caddy
,memcached
,beanstalkd
,beanstalkd-console
,workspace
-
Enter the Workspace container, to execute commands like (Artisan, Composer, PHPUnit, Gulp, ...).
docker-compose exec workspace bash
-
If you don't have a Laravel project installed yet, follow the step to install Laravel from a Docker container.
a. Enter the Workspace container.
b. Install Laravel.
composer create-project laravel/laravel my-cool-app "5.3.*"
-
Edit the Laravel configurations. Open your Laravel's .env file and set the DB_HOST to your mysql:
DB_HOST=mysql
-
Open your browser and visit your localhost address.
-
-
Open routes file. Paste the following code in:
Route::get('helloworld', function () { return '<h1>Hello World</h1>'; });
after going to route
localhost/helloworld
it displays Hello World.The routes file is located:
5.3routes/web.php
5.25.1 (LTS)5.0app/Http/routes.php
4.2app/routes.php
-
-
Create a Laravel application:
$ composer create-project laravel/laravel hello-world
-
Create a controller:
$ php artisan make:controller HelloController --resource
This will create the file app/Http/Controllers/HelloController.php. The
--resource
option will generate CRUD methods for the controller, e.g. index, create, show, update. -
Register a route to HelloController's
index
method. Add this line to app/Http/routes.php:Route::get('/hello', 'HelloController@index');
To see your newly added routes, you can run
$ php artisan route:list
-
Create a Blade template in the
views
directory:resources/views/hello.blade.php:
<h1>Hello world!</h1>
-
Now we tell index method to display the hello.blade.php template:
app/Http/Controllers/HelloController.php
// ... public function index() { return view('hello'); } // ...
Now you can open up
http://localhost/hello-world/public/hello
in your browser.Alternatively, you can serve your app using
php artisan serve
, then visithttp://localhost:8000
. -
Remarks
Created by Taylor Otwell as a free open-source PHP web framework, Laravel is meant to ease and accelerate the development process of web applications with a great taste for simplicity.
It follows the model–view–controller (MVC) architectural pattern as well as the PSR-2 coding standard, and the PSR-4 autoloading standard.
Running a Test Driven Development (TDD) in Laravel is fun and easy to implement.
Hosted on GitHub and available at https://github.com/laravel/laravel, Laravel boasts of a micro-services architecture, making it tremendously extendable and this, with ease, with the use of custom-made and or existing third-party packages.
Main Features
MVC
Laravel uses the MVC model, therefore there are three core-parts of the framework which work together: models, views and controllers. Controllers are the main part where most of the work is done. They connect to models to get, create or update data and display the results on views, which contain the actual HTML structure of the application.
Routing & Middleware
You can define the URLs of your application with the help of routes. These routes can contain variable data, connect to controllers or can be wrapped into middlewares. Middelware is a mechanism for filtering HTTP requests. They can be used to interact with requests before they reach the controllers and can thus modify or reject requests.
Artisan
Artisan is the command line tool you can use to control parts of Laravel. There are a lot of commands available to create models, controllers and other resources needed for development. You can also write your own commands to extend the Artisan command line tool.
Eloquent ORM
To connect your models to various types of databases, Laravel offers its own ORM with a large set of functions to work with. The framework also provides migration and seeding and also features rollbacks.
Event Handling
The framework is capable of handling events across the application. You can create event listeners and event handlers that are similar to the ones from NodeJs.
Versions
Version | Release Date |
---|---|
1.0 | 2011-06-09 |
2.0 | 2011-11-24 |
3.0 | 2012-02-22 |
3.1 | 2012-03-27 |
3.2 | 2012-05-22 |
4.0 | 2013-05-28 |
4.1 | 2013-12-12 |
4.2 | 2014-06-01 |
5.0 | 2015-02-04 |
5.1 (LTS) | 2015-06-09 |
5.2 | 2015-12-21 |
5.3 | 2016-08-24 |
Laravel 5.1 is the first release to receive long term support (LTS); it will receive bug fixes for 2 years and security fixes for 3 years.
Topic Outline
- Installation
- Requirements
- Installation using LaraDock (Laravel Homestead for Docker)
- Hello World Example (Basic)
- Hello World Example (Using Controller and View)
Versions
Sign up or log in
Save edit as a guest
Join Stack Overflow
Using Google
Using Facebook
Using Email and Password
We recognize you from another Stack Exchange Network site!
Join and Save Draft