Laravel8在api请求时返回群错误

我被一个我无法理解的错误困住了,Laravel 8 响应总是"flock() expects parameter 1 to be resource, bool given"在所有 api 路由中。我做了一个简单的方法来调试这个问题,但我不知道问题是什么,所以如果有人能给我一些帮助,我会很棒。这是我的代码:

API 路由

Route::post('/createUser',[UserController::class, 'store'])->name('createUser');
Route::get('/getUser',[UserController::class, 'index'])->name('getUser');

Route::middleware(['auth:sanctum'])->group(function () {
    Route::prefix('V1')->group(function () {
        
        // Rutas para los VDP
        Route::get('/conf',[ReaderController::class, 'readerInitialConf'])->name('readerInitialConf');
        Route::post('/createReader',[ReaderController::class, 'store'])->name('createReader');


    });
}); 

控制器代码:

public function index()
    {
        return User::all();
    }

这是邮递员:

注意:这个应用程序是 dockerized,我不知道 docker 是否会导致这个问题,但我认为不会,因为我总是使用它并且从来没有遇到过这个问题。

如果有人可以提供帮助,我将非常感激。

提前致谢!劳尔

回答

检查权限storage/framework/cache/data仅定义 777storage/framework/cache是不够的,您还应该授予webserver用户写入该文件夹的权限,通常用户是:www-data_www

正确的做法是拥有775此文件夹的权限,然后仅更改组以允许您的用户和网络服务器用户写入这些文件夹。

chmod 775 storage/framework/cache
chmod 775 storage/framework/cache/data

sudo chgrp www-data storage/framework/cache
sudo chgrp www-data storage/framework/cache/data


以上是Laravel8在api请求时返回群错误的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>