Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
development:php:laravel [2020/02/27 14:44] kalenpw created |
development:php:laravel [2021/06/29 15:15] (current) kalenpw [Add column to existing table] |
||
---|---|---|---|
Line 10: | Line 10: | ||
php artisan key: | php artisan key: | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ | ===== CORS ===== | ||
+ | [[https:// | ||
+ | <code bash> | ||
+ | composer require barryvdh/ | ||
+ | </ | ||
+ | |||
+ | To allow CORS for all routes, add the HandleCors middleware in the '' | ||
+ | <code php> | ||
+ | protected $middleware = [ | ||
+ | // ... | ||
+ | \Barryvdh\Cors\HandleCors:: | ||
+ | ]; | ||
+ | </ | ||
+ | |||
+ | To allow CORS on a specific middleware group or route, add the HandleCors middleware to your group: | ||
+ | <code php> | ||
+ | protected $middlewareGroups = [ | ||
+ | ' | ||
+ | // ... | ||
+ | ], | ||
+ | |||
+ | ' | ||
+ | // ... | ||
+ | \Barryvdh\Cors\HandleCors:: | ||
+ | ], | ||
+ | ]; | ||
+ | </ | ||
+ | |||
+ | Configure CORS | ||
+ | <code bash> | ||
+ | php artisan vendor: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | ===== Database ===== | ||
+ | ** Add column to existing table ** \\ | ||
+ | <code bash> | ||
+ | php artisan make: | ||
+ | </ | ||
+ | <code php> | ||
+ | public function up() | ||
+ | { | ||
+ | Schema:: | ||
+ | $table-> | ||
+ | // to set default value: | ||
+ | $table-> | ||
+ | }); | ||
+ | } | ||
+ | </ | ||
+ | and a rollback option | ||
+ | <code php> | ||
+ | public function down() | ||
+ | { | ||
+ | Schema:: | ||
+ | $table-> | ||
+ | }); | ||
+ | } | ||
+ | </ | ||
+ | then run migration | ||
+ | <code bash> | ||
+ | php artisan migrate | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | ===== Order By ===== | ||
+ | <code php> | ||
+ | $users = DB:: | ||
+ | -> | ||
+ | ->get(); | ||
+ | // or | ||
+ | |||
+ | $projects = \App\Project:: | ||
+ | </ | ||
+ | |||
+ | ---- |