Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
development:php:laravel [2020/02/27 14:47]
kalenpw
development:php:laravel [2021/06/29 15:15] (current)
kalenpw [Add column to existing table]
Line 18: Line 18:
 </code> </code>
  
-To allow CORS for all routes, add the HandleCors middleware in the $middleware property of app/Http/Kernel.php class:+To allow CORS for all routes, add the HandleCors middleware in the ''$middleware'' property of ''app/Http/Kernel.php'' class:
 <code php> <code php>
 protected $middleware = [ protected $middleware = [
Line 44: Line 44:
 php artisan vendor:publish --provider="Barryvdh\Cors\ServiceProvider" php artisan vendor:publish --provider="Barryvdh\Cors\ServiceProvider"
 </code> </code>
 +
 +----
 +===== Database =====
 +** Add column to existing table ** \\
 +<code bash>
 +php artisan make:migration add_paid_to_users
 +</code>
 +<code php>
 +public function up()
 +{
 +    Schema::table('users', function($table) {
 +        $table->integer('paid');
 +        // to set default value:
 +        $table->integer('paid')->default(0);
 +    });
 +}
 +</code>
 +and a rollback option
 +<code php>
 +public function down()
 +{
 +    Schema::table('users', function($table) {
 +        $table->dropColumn('paid');
 +    });
 +}
 +</code>
 +then run migration
 +<code bash>
 +php artisan migrate
 +</code>
 +
 +----
 +===== Order By =====
 +<code php>
 +$users = DB::table('users')
 +                ->orderBy('name', 'desc')
 +                ->get();
 +// or
 +
 +$projects = \App\Project::orderBy('order')->get();
 +</code>
 +
 +----