我在 github 上创建了一个存储库并想推送我的代码,但得到了以下提示:
$ git push -u origin master
no such identity: id_rsa: No such file or directory
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
但是 id_rsa 文件是存在的,我尝试再次将 id_rsa 公钥添加到我的 github 设置中,github 告诉我这个 public 已被使用。
$ ls
config id_rsa id_rsa.pub known_hosts
Run Code Online (Sandbox Code Playgroud)
这是我的.ssh/文件夹
配置文件包含到不同 git 站点的 serval git 配置。所有人都使用相同的公钥,他们可以成功地工作。
我做了什么:
$git init
$git add .
$git commit -m "first commit"
$git …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用 Laravel,我真的很困惑,service contains并service providers搜索了一些示例,例如以下服务代码:
namespace App\Service;
class Tests
{
public function test()
{
echo "aaa";
}
}
Run Code Online (Sandbox Code Playgroud)
服务提供者代码
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class TestServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register services.
*
* @return void
*/
public function register()
{
//
$this->app->bind('App\Service\Tests', function($app){
return new \App\Service\Tests();
});
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将这个提供者添加到config/app,php->providers
然后我创建了一个控制器
namespace App\Http\Controllers\test;
use App\Http\Controllers\Controller;
use App\Service\Tests as …Run Code Online (Sandbox Code Playgroud) 我的大部分数据库表包含create_user_id和update_user_id
当我使用save(), update(), insert(),createOrUpdate()和 etc 方法时,我如何自动更新这两个字段。
例如,我执行这个脚本:
$model = Model::find(1);
$model->model_f = 'update';
$model->save();
Run Code Online (Sandbox Code Playgroud)
然后这个记录model_f更新了,也update_user_id更新了。
我知道 eloquent 可以update_time自动管理并且我已经使用过它。但是我想在更新或插入或删除时做其他事情
PS:我有一个常量命名USERID来记住当前用户的ID
我正在用 5.7 开始一个新的 Laravel 项目,但是有一个问题,当我first()用来获取数据时,如果数据不存在,它将返回null,然后执行toArray()会抛出一个 PHP 错误。所以我使用以下代码来重新喜欢它。
$user_model = \App\Model\User::where('id', $id);
if ($select) {
$user_model->select(explode(',', $select));
}
$user_data = $user_model->first();
$user_data = $user_data ?? $user_data->toArray();
Run Code Online (Sandbox Code Playgroud)
那么有没有更好的办法呢?