我在本地服务器上安装了 laravel 7。当我运行php artisan route:cache命令时,laravel 返回错误:
逻辑异常
无法为序列化准备路由 [api/user]。使用闭包。
我该如何解决这个问题?
我尝试通过运行工匠命令:
php artisan config:cache
php artisan config:clear
php artisan cache:clear
composer dumpautoload
Run Code Online (Sandbox Code Playgroud)
这是内容routes/api.php:
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/user', function (Request $request) …Run Code Online (Sandbox Code Playgroud) 我在尝试使用观察者时遇到一个问题,它不会仅在更新的情况下触发观察者。在其他情况下它工作得很好!
我对此进行了一些研究,找到了一些解决方案,例如直接从模型调用更新方法,而不是在存储库中,但不幸的是,它对我不起作用。我找到的解决方案:https://github.com/laravel/framework/issues/11777#issuecomment-170388067
用户观察者class UserObserver
{
/**
* Handle the user "created" event.
*
* @param \App\Models\User $user
* @return void
*/
public function created(User $user)
{
dd($user);
}
/**
* Handle the user "updated" event.
*
* @param \App\Models\User $user
* @return void
*/
public function updated(User $user)
{
dd($user);
}
/**
* Handle the user "deleted" event.
*
* @param \App\Models\User $user
* @return void
*/
public function deleted(User $user)
{
dd($user);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的AppServiceProvider: …
我在尝试全局安装 Laravel 时出错。
当我写composer global require laravel/installer
我得到这个错误:
Problem 1
- Installation request for laravel/installer ^3.1 -> satisfiable by laravel/installer[v3.1.0].
- Conclusion: remove symfony/console v3.4.38
- Conclusion: don't install symfony/console v3.4.38
- laravel/installer v3.1.0 requires symfony/console ^4.0|^5.0 -> satisfiable by symfony/console[v4.0.0, v4.0.1, v4.0.10, v4.0.11, v4.0.12, v4.0.13, v4.0.14, v4.0.15, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.2, v4.1.3, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0, v4.2.1, v4.2.10, v4.2.11, v4.2.12, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, …Run Code Online (Sandbox Code Playgroud) 我正在使用 Laravel 并且我有功能迁移:
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->unique();
$table->string('slug')->unique();
$table->string('subtitle');
$table->integer('price');
$table->text('description');
$table->boolean('featured')->default(false);
$table->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud)
当我在我的 cmd 上执行“php artisan migrate”时出现错误
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1071 La clé est trop longue. Longueur maximale: 1000 (SQL: alter table `users` add unique `users_username_unique`(`username`))
at C:\Users\linda\lynda-master\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the …Run Code Online (Sandbox Code Playgroud)