Laravel Quick Start

Quick reminder of steps to setup a Laravel project on Ubuntu/Linux Mint and similar.

First install composer:

sudo apt install composer

Install PHP dependencies:

sudo apt install php-cli-prompt php-common php-composer-semver php-composer-spdx-licenses php-fpm php-json-schema php-mysql php-symfony-console php-symfony-filesystem php-symfony-finder php-symfony-process php7.0-cli php7.0-common php7.0-fpm php7.0-gd php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline php7.0-xml php7.0-zip php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-mysql

 

Use composer to create your Laravel project:

composer create-project --prefer-dist laravel/laravel myprojectname

Install composer.json packages:

composer install

Generate a key for your new project into the .env file:

php artisan key:generate

Amend the .env file with database details and anything else you want to customise. You may want to install mysql with

sudo apt install mysql-server

Auth Scaffolding

Create the login and register views, migrations etc:

php artisan make:auth

Test the project:

php artisan serve

Databases

Add more migrations with:
php artisan make:migration create_posts_table

An example table create is shown beloe:
Schema::create('images', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('image_id');
$table->integer('venue_id')->index();
$table->boolean('image_is_active')->default(1);
$table->double('lat', 15, 8)->nullable();
$table->timestamps();
});

To seed the database with entries create a seeder

php artisan make:seeder ImagesTableSeeder


DB::table('images')->insert([
'image_id' => 1,
'venue_id' => 1,
'image_is_active' => 1,
'image_lat' => '54.5764326',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);

Then to perform the seedings use:

php artisan db:seed

 

Creating Models and Controllers

To generate a new model use:
php artisan make:model Image
The model code is generated and can be expanded as below:

namespace App;
use Illuminate\Database\Eloquent\Model;

class Image extends Model
{
protected $primaryKey = 'image_id';
protected $fillable = [ 'venue_id', 'image_is_active','image_block','image_row','image_seats','image_filename','image_thumbnail','image_width',
'image_height', 'image_type','image_uploaded_by','image_lat','image_lng','created_at' ];

public function venues(){
return $this=>belongsTo('Venue');
}

}

The line below creates a controller with functions for update, create, delete etc:
php artisan make:controller --resource ImageController

Adding Composer Components

Add the entry in the composer.json file then install:

composer install --prefer-dist

Add entries to the config/app.php file under the ‘providers’ array and ‘aliases’ arrary.

Then publish the config files:

php artisan vendor:publish

php laravel vendor publish

 

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>