小编Dex*_*gil的帖子

如何删除Laravel 5中的会话

我正在尝试删除基本会话,但它不会删除.这是代码

welcome.blade.php

@if(Session::has('key'))             
    {{ Session::get('key')}}
    <a href="logout">Sign Out</a>

    @else
        please signin

    @endif
</div>
Run Code Online (Sandbox Code Playgroud)

我不知道如何删除会话.这是我用过的那个,但它不起作用route.php

Route::get('/logout', function() {

   $vv =  Session::forget('key');
   if($vv)
   {
        return "signout";
   }
});
Run Code Online (Sandbox Code Playgroud)

php laravel-5

8
推荐指数
2
解决办法
4万
查看次数

Laravel 5单元测试 - 在null上调用成员函数connection()

我尝试为我UserShop模型之间的关系创建单元测试,但是当我运行vendor\\bin\\phpunit这个错误时,我不知道这个,因为我是单元测试的新手.我试图在我的控制器上运行我的代码以查看关系是否真的有效,幸运的是它按预期工作,但在phpunit中运行时却没有.这个phpunit没有与Models一起工作,我做错了什么?

Fatal error: Uncaught Error: Call to a member function connection() on null in E:\projects\try\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:1013

Stack trace: E:\projects\try\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(979): Illuminate\Database\Eloquent\Model::resolveConnection(NULL)

这是我的UserTest.php

<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

use App\User;
use App\Shop;

class UserTest extends TestCase
{

    protected $user, $shop;

    function __construct()
    {
        $this->setUp();
    }

    function setUp()
    {
        $user = new User([
            'id' => 1,
            'first_name' => 'John',
            'last_name' => 'Doe',
            'email' => 'JohnDoe@example.com',
            'password' => 'secret',
            'facebook_id' => null,
            'type' => 'customer', …
Run Code Online (Sandbox Code Playgroud)

php phpunit unit-testing eloquent laravel-5.4

7
推荐指数
4
解决办法
6255
查看次数

如何在控制器Laravel上打印出值?

我是Laravel的初学者......

如何在Laravel上的控制器上调试一些值,结果可以console.log()在javascript上显示控制台的语法?

示例控制器功能:

class TestMeController extends Controller {
    public function __construct()
    {
        $this->middleware('jsonify');
    }

    public function callMe($id)
    {
        $params = Request::all();

        console.log($id);  <== how to write code on Laravel?
    }
}
Run Code Online (Sandbox Code Playgroud)

php printing console laravel console.log

6
推荐指数
2
解决办法
2万
查看次数

在共享托管子目录上部署 Laravel

我正在尝试将 laravel 5.5 部署在共享主机上的 WordPress 子目录中。我尝试了谷歌的太多建议,但仍然无法使其发挥作用。它总是返回 404 错误。WordPress 已安装在内部/public_html ,我需要安装 Laravel,/public_html/my-laravel-app 这是我的.htaccess文件的外观:

/public_html/.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# protect wpconfig.php
<files wp-config.php>
order allow,deny
deny from all
</files>

# protect the htaccess file
<files .htaccess>
order allow,deny
deny from all
</files>

# disable the server signature
ServerSignature Off
Run Code Online (Sandbox Code Playgroud)

/public_html/my-laravel-app/.htaccess

<IfModule mod_rewrite.c>
   RewriteEngine On …
Run Code Online (Sandbox Code Playgroud)

php wordpress .htaccess shared-hosting laravel

5
推荐指数
1
解决办法
9607
查看次数

Laravel 5如果密码重置令牌已过期,如何检查密码重置令牌

我正在使用Laravel 5开发一个Web应用程序,我使用了Laravel的make:auth脚手架.我能够使用令牌发送密码重置链接,这在我的结束时运行良好.点击重置链接后,我有这种网址:http://example.com/password/reset/{reset_token}.现在,在我的auth.reset刀片文件中,我想首先检查是否{reset_token}已经过期,因为它似乎在60分钟的到期时间内config.auth.php,它似乎不会自动删除过期的令牌.所以,我正在尝试制作一个手动功能来检查重置令牌是否仍然有效:

function validateReminderToken($token)
{
    // I want to add some filter here like
    // if (tokenExpired($token)) return false;     
    $res = DB::table('password_resets')->where('token', $token)->get();
    if (empty($res)  || $res === null) {
        return false;
    }

    $res = $res[0];
    return $res->email;
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做?是否有一些内置的方法来检查令牌是否已过期?谢谢.

php laravel laravel-5

4
推荐指数
3
解决办法
1万
查看次数

Laravel 5.7无法找到名称为[factory] ​​[App\User]的工厂

Laravel 5.7工厂发生了什么?当我在工厂上运行php artisan tinker它工作正常.但是当我在单元测试中使用它时会抛出一个错误:

Unable to locate factory with name [default] [App\User]

这是我的单元测试

<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use \App\User;

class UserTest extends TestCase
{
    use DatabaseTransactions;

    public function setUp()
    {
        $this->user = factory(User::class, 1)->create()->first();
    }

    /**
     * @test
     */
    public function a_sample_test()
    {
        $this->assertTrue(!empty($this->user));

    }
}
Run Code Online (Sandbox Code Playgroud)

并且UserFactory是通过运行生成的 php artisan make:factory UserFactory --model=User

这是我的用户/数据库/工厂的工​​厂

<?php

use Faker\Generator as Faker;

$factory->define(\App\User::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail, …
Run Code Online (Sandbox Code Playgroud)

php unit-testing factory laravel laravel-5.7

3
推荐指数
2
解决办法
2139
查看次数

在Laravel中测试多重身份验证

在我的应用程序中,我使用了多重身份验证。(我使用了此链接

它有效,并且我可以以用户身份登录->我被重定向到“ / home”

以管理员身份,登录时,我被重定向到“ / admin_home”

连接后,管理员无法访问“ / home”,他被重定向到另一个页面

但是当我编写此测试时:

class AdminTest extends TestCase
{
    public function setUp()
    {
        parent::setUp();
        Artisan::call('migrate');
        Artisan::call('db:seed');
    }

    public function tearDown()
    {
        Artisan::call('migrate:reset');
        parent::tearDown();
    }


    public function testCannotAccessUserSpace()
    {
        $admin = Admin::find(1);

        $response = $this->actingAs($admin, 'admin')
            ->get('/home');

        $response->assertStatus(200);
    }

}
Run Code Online (Sandbox Code Playgroud)

我有一个成功的响应,但我知道管理员无法访问“家庭”空间

我的考试有什么问题?

testing laravel

2
推荐指数
1
解决办法
494
查看次数

JS - 单击按钮将元素的文本更改为undefined

单击"hi"和"helo"按钮必须'.admin-text'根据计划更改相应文本的内容,但只需将其更改为'undefined'.

var admin_text = document.querySelector('.admin-text');

var infra_btns = [document.getElementById('hi'), document.getElementById('helo')];


var infra_html = ["<p>hi</p>", "<p>helo</p>"];

for(var i = 0; i < 2; i++)
{
  infra_btns[i].addEventListener('click', function() {
    admin_text.innerHTML = infra_html[i];
  });
}
Run Code Online (Sandbox Code Playgroud)
<div class="admin">
  <div class="admin-nav">
    <button class="adminbtns" id="hi">hi</button>
    <button class="adminbtns" id="helo">helo</button>
  </div>

  <div class="admin-text">

  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

html javascript

0
推荐指数
1
解决办法
103
查看次数

AWS EB CLI - 每次运行“eb部署”时排除特定文件夹

如何防止每次部署中特定文件夹被替换?考虑下面的目录结构:

-- /.ebextensions
-- /app
-- /database
-- /public
---- /css
---- /js
---- /images
Run Code Online (Sandbox Code Playgroud)

我正在为我的 PHP 应用程序使用 AWS CodeCommit 和 EB CLI,每次运行时eb deploy这些文件和目录都会被替换,因此我想排除该/public/images目录,以便以前上传的图像在更新版本后仍然存在已部署。

我整个星期都在研究他们的文档,但找不到任何可能的解决方案。Elastic Beanstalk 可以做到这一点吗?或者任何关于在 AWS 中部署的替代建议将非常感激。提前致谢!

php amazon-web-services laravel aws-codecommit ebcli

0
推荐指数
1
解决办法
1222
查看次数