Laravel
Create Project
# new project composer create-project --prefer-dist laravel/laravel PROJECT_NAME # if cloning repo you likely will need to generate a key php artisan key:generate --ansi
CORS
composer require barryvdh/laravel-cors
To allow CORS for all routes, add the HandleCors middleware in the $middleware
property of app/Http/Kernel.php
class:
protected $middleware = [ // ... \Barryvdh\Cors\HandleCors::class, ];
To allow CORS on a specific middleware group or route, add the HandleCors middleware to your group:
protected $middlewareGroups = [ 'web' => [ // ... ], 'api' => [ // ... \Barryvdh\Cors\HandleCors::class, ], ];
Configure CORS
php artisan vendor:publish --provider="Barryvdh\Cors\ServiceProvider"
Database
Add column to existing table
php artisan make:migration add_paid_to_users
public function up() { Schema::table('users', function($table) { $table->integer('paid'); // to set default value: $table->integer('paid')->default(0); }); }
and a rollback option
public function down() { Schema::table('users', function($table) { $table->dropColumn('paid'); }); }
then run migration
php artisan migrate
Order By
$users = DB::table('users') ->orderBy('name', 'desc') ->get(); // or $projects = \App\Project::orderBy('order')->get();