在shell中我可以像这样创建数据库迁移(例如):
./artisan migrate:make --table="mytable" mymigration
Run Code Online (Sandbox Code Playgroud)
使用Artisan :: call()我无法弄清楚如何传递非参数参数(在本例中为"mymigration").我尝试了以下代码的许多变体:
Artisan::call('db:migrate', ['--table' => 'mytable', 'mymigration'])
Run Code Online (Sandbox Code Playgroud)
有人有任何想法吗?我一直在使用shell_exec('./ artisan ......')但我对这种方法并不满意.
有没有办法检测用户在创建自定义工匠命令时指定的详细级别?我在文档中没有看到任何关于它的内容.
我试图完全理解Laravel(5.1)artisan optimize命令和最佳实践,但文档似乎缺乏.我没有在生产服务器上安装Composer,因此,具体来说,我想知道artisan optimize --force在开发上运行时要修改或创建的文件必须推送到生产环境.目标不是炸毁生产中的应用程序!运行该命令后,我看到以下文件已被修改:
\bootstrap\cache\compiled.php
\vendor\composer\ - the entire directory
\vendor\autoload.php
Run Code Online (Sandbox Code Playgroud)
我是否在思考这个问题,或者我只是将这些文件推向生产状态并且我很乐意去做?此外,什么是何时运行的最佳做法artisan optimize?每次创建新模型?控制器,路由和帮助程序类怎么样?
最后,我看到\bootstrap\cache\compiled.php文件高达548KB,差不多17K!这真的被认为是最佳的吗?
我似乎不明白为什么我们需要运行一个Laravel应用程序,php artisan serve只需用Apache或nginx运行它.我知道在开发过程中,我们使用artisan来启动站点,在部署到服务器之后,您使用Web服务器来加载站点.
什么是首先在工匠中运行应用程序的用途?
所以我php artisan db:seed在迁移我的数据库之后尝试了一个基本但是它一直在cmd中返回标题错误 -[Symfony\Component\Debug\Exception\FatalErrorException] Class 'User' not found
我试过的事情
db:seed函数之前的php dump-autoload--seed语法重新运行它以下是迁移
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
Run Code Online (Sandbox Code Playgroud)
我相信这里的一切都是正确的,现在这里是 …
我migrations从一个名为Laravel 5.4的数据库中删除了该表laravel.当我跑php artisan migrate:install,我得到这个错误:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from
information_schema.tables where table_schema = laravel
and table_name = migrations)
Run Code Online (Sandbox Code Playgroud)
我删除并重新创建了数据库.我也跑了composer update.没运气.我可以在phpMyAdmin中运行该命令并手动创建表.
假设我有三个我想要安排的命令:'commandA','commandB'和'commandC'
但是我不想在'commandA'完成之前运行'commandB',我不想在'commandB'完成之前运行'commandC'.
我知道我可以安排每个人每五分钟跑一次:
$schedule->command('commandA')->everyFiveMinutes();
$schedule->command('commandB')->everyFiveMinutes();
$schedule->command('commandC')->everyFiveMinutes();
Run Code Online (Sandbox Code Playgroud)
但有可能一个接一个地链接它们吗?
我在新的Laravel,并试图通过编码学习.我创建了迁移和种子,当我从终端调用它们时工作正常,但是我想在我的HomeController中尝试这个代码,我得到了一个很大的错误.
错误
FatalErrorException in HomeController.php line 23:
Class 'App\Http\Controllers\Artisan' not found
Run Code Online (Sandbox Code Playgroud)
家庭控制器中的代码
$hasTable = Schema::hasTable('users');
if ($hasTable==0)
{
echo "call cli to migration and seed";
$migrate = Artisan::call('migrate');
$seed = Artisan::call('db:seed');
echo "Migrate<br>";
print_r($migrate);
echo "Seed<br>";
print_r($seed);
}
Run Code Online (Sandbox Code Playgroud)
我相信,如果我加载正确的命名空间,我可以避免这个错误,但我不确定.
我正在使用Laravel,作为我的部署例程的一部分,我有命令
RUN php artisan migrate
因为我正在制作中,所以我得到了错误
在生产中应用,命令取消!
修复很简单:RUN php rankbot/artisan migrate --force但我觉得这不是正确的方法吗?确保数据库架构始终是最新的最佳方法是什么?
我有一个订单表和一个sell_shipping_labels引用orders.id作为外国的.但是,当我运行Laravel迁移时,我得到了可怕的错误代码:
[Illuminate\Database\QueryException]
SQLSTATE [HY000]:常规错误:1005无法创建表cheapbooks_test.#sql-b5b_b2a(错误:150"外键约束形成错误")(SQL:alter tablesell_shipping_labelsadd constraintsell_shipping_labels_order_id_foreignforeign key(order_id)referencesorders(id))[Doctrine\DBAL\Driver\PDOException]
SQLSTATE [HY000]:常规错误:1005无法创建表cheapbooks_test.#sql-b5b_b2a(错误:150"外键约束形成错误")
这是我的orders表架构:
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('book_id');
$table->integer('status_id');
$table->double('payment_amount')->nullable();
$table->timestamp('received_at')->nullable();
$table->timestamp('paid_at')->nullable();
$table->timestamps();
$table->softDeletes();
});
Run Code Online (Sandbox Code Playgroud)
这是我的sell_shipping_labels架构:
Schema::create('sell_shipping_labels', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('order_id');
$table->string('shippo_object_id');
$table->string('label_url');
$table->string('tracking_url');
$table->string('tracking_number');
$table->timestamp('arrived_at');
$table->timestamps();
$table->softDeletes();
$table->foreign('order_id')->references('id')->on('orders');
});
}
Run Code Online (Sandbox Code Playgroud)
现在我已经颠倒了互联网,试图找出问题所在.关于这个问题的所有帖子都指的是必须在具有外键的表之前创建订单表,但这对我来说不是问题,因为我的文件的顺序正确.
artisan ×10
laravel ×9
php ×6
laravel-5 ×3
apache ×1
laravel-5.1 ×1
laravel-5.4 ×1
migrate ×1
mysql ×1
namespaces ×1
optimization ×1
verbosity ×1