标签: laravel-5

Laravel Carbon:为什么 now() 提前 1 天?

我在播种机中使用它:

'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
Run Code Online (Sandbox Code Playgroud)

我得到了正确的日期/时间,但正好提前了 1 天。

我试过了:

Carbon::now(new DateTimeZone('America/Chicago')),
Run Code Online (Sandbox Code Playgroud)

在我的播种机文件中,它似乎有效。但是,当我从控制器插入记录时,日期不正确。

我正在$table->timestamps();用来创建列 - 是否有可以输入正确时区的配置设置?或者,还有什么我做错了吗?

php-carbon laravel-5

-1
推荐指数
1
解决办法
303
查看次数

Laravel 5 复制/克隆数据库表。产品克隆

我想通过单击按钮从我的数据库中克隆产品。

例子:

在我的产品列表中,我成功创建了一个项目。我现在想添加第二个类似的项目,但不想创建新产品并再次填写字段(需要时间)。我现在想在我的 Laravel 5 商店中添加一个按钮,在其中复制或克隆我在成功之前创建的项目。

只是一个具有其他产品 ID 但所有其他信息相同的新数据库表。

什么是最好的方法来做到这一点?

非常感谢

php mysql laravel laravel-5

-1
推荐指数
1
解决办法
1897
查看次数

Laravel介于两者之间

我写了一个Laravel查询.我使用whereBetween,并orWhereBetween伴随着一个where名为"共享"列上声明,应返回一行.
但是这个查询没有考虑where条件.它只花了whereBetweenorWhereBetween.可能是什么原因.

我的查询

$childs = Program::whereIn('id', $programs_by_date)
                ->where('shareable', '=','1')
                ->wherebetween('starting_date', [$new_start_date,$new_end_date])
                ->orwherebetween('ending_date', [$new_start_date,$new_end_date])
                ->orderBy('starting_date')
                ->get(); 
Run Code Online (Sandbox Code Playgroud)

->where('shareable', '=','1')返回0行.可能是什么原因.

shareable 类型是枚举

mysql laravel laravel-4 laravel-5

-1
推荐指数
1
解决办法
655
查看次数

我如何在 Laravel 中使用 faker 随机生成一个 id 或 null?

我正在尝试使用同一个表的随机 id 为 parent_id 列设置种子,或者让它为空。

这我认为它会起作用:

...
'parent_id' => $faker->boolean() ? Page::all()->random()->id : null,
...
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

  You requested 1 items, but there are only 0 items available. 
Run Code Online (Sandbox Code Playgroud)

有谁知道如何做到这一点?

更新1:

使用伪动漫答案我尝试了流动:

$factory->define(Page::class, function (Faker\Generator $faker) {
...
    $parent_id = null;
...
    $has_parent = $faker->boolean(50);
    Log::debug('$has_parent' . $has_parent);
    if ($has_parent) {
        $parents = Page::all();
        Log::debug('$parents' . count($parents));

        if ($parents->isEmpty()) {
            Log::debug('isEmpty');

            $parent_id = null;
        } else {
            Log::debug('$parents->random()' . print_r($parents->random(), true));
            $parent_id = $parents->random()->id;
        }
    }

    return [
...

        'parent_id' => $parent_id, …
Run Code Online (Sandbox Code Playgroud)

seeding faker laravel laravel-5

-1
推荐指数
3
解决办法
8910
查看次数

Laravel使用GET方法进行身份验证

在我的laravel项目中,我使用zizaco / entrust进行基于角色的身份验证。我有两个角色admin和user。现在我希望用户可以登录两个过程。laravel中正常登录系统的一个过程(运行良好), 当用户设置此url时,另一个过程使用诸如
http:// myproject / login?username = username&password = password之类的get方法,然后调用登录路径,以获取电子邮件和密码url的用户名和密码,并在匹配数据登录用户后成功。现在我要问的是,我该如何处理第二个进程从用户登录。我可以遵循任何技术吗?

php authentication laravel-5

-1
推荐指数
1
解决办法
100
查看次数

Laravel中的中间件是什么?

在应用任何应用程序/业务逻辑之前,Laravel中的中间件可用于添加应用程序范围的逻辑(或特定于特定路由或一组路由)。我想做同样的事情,但是在完成所有应用程序/业务逻辑之后。我对中间件的爱好是,它将中间件集中在应用所述逻辑的位置。在请求/响应生命周期结束时,有没有办法做到这一点?

一种选择是使用变压器,但由于某种原因,我发现它不如中间件那么干净(也许是因为它是由第三方完成的?)

示例用例:我希望有一组端点始终以替代货币而不是美元返回值,仅当来自某个地理区域(我已经知道)的某种类型的购物者提出此类请求时。因此,我将需要执行业务逻辑,然后在我将JSON响应发回之前,我想“劫持”该响应并将所有USD值替换为我选择的另一种货币。

有想法吗?(我正在使用Laravel 5.5)

php transformer-model laravel laravel-5

-1
推荐指数
1
解决办法
82
查看次数

如何从 Laravel 5.2 中的另一个控制器调用控制器函数?

我在 Laravel 5.2 中有 2 个控制器

1) Apiauth 控制器

   <?php

   namespace App\Http\Controllers;

   use Illuminate\Http\Request;

   use App\Http\Requests;
   use App\Api_auth;

   class Apiauth extends Controller
   {
       public function checkauth($reqauthkey)
       {
             $authkey=Api_auth::orderBy('id', 'desc')->first();


             if($authkey->authkey!=$reqauthkey)
            return response()->json(['response'=>'false','message'=>'Authentication Failed','code'=>403],403);  
        }

 }
Run Code Online (Sandbox Code Playgroud)

2) 移动注册控制器

        namespace App\Http\Controllers;


        use Illuminate\Http\Request;
        use App\Http\Controllers\Apiauth;
        use App\Http\Requests;
        use App\Mobile_registration;
        use App\Api_auth;

        use App\Http\Requests\CreateMobileRegistrationRequest;

        class MobileregistrationController extends Controller
        {

            public function index(Request $request)
            {

                App\Http\Controllers\Apiauth->checkauth($request->authkey);

                // $authkey=Api_auth::orderBy('id', 'desc')->first();


                // if($authkey->authkey!=$request->authkey)
                //     return response()->json(['response'=>'false','message'=>'Authentication Failed','code'=>403],403);    

                $mobileregistration=Mobile_registration::all();


                if($mobileregistration->isEmpty())
                    return response()->json(['response'=>'false','message'=>'No data found','code'=>404],404);
                else
                    return response()->json(['response'=>'true','data'=>$mobileregistration],200); …
Run Code Online (Sandbox Code Playgroud)

php api laravel laravel-5

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

如何将 Laravel-5.6 转换为 .exe

我正在 localhost 中加载项目,我的管理员要求我将 laravel 5.6 与 mysql 一起转换为 .exe。

我是新来的,不知道。哪位高手可以指导一下....

提前致谢。

laravel laravel-5 laravel-5.6

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

前导0被删除

我有一个问题,在我使用Laravel的14个月中从未遇到过。

我有一个用户注册系统。任何应用程序权利的基本要求。我有通常的凭据名称,用户名,电子邮件,密码和电话号码。

如果我以以下格式提交号码086123456。则从数据库中保存的内容中删除了前导0。phone_number字段是整数。

不知道这是怎么回事。

用户模型

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Property;
use Tymon\JWTAuth\Contracts\JWTSubject;


class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    protected $fillable = [
        'first_name', 'last_name', 'username', 'email', 'phone_number', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function properties()
    {
        return $this->hasMany(Property::class);
    }

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }
}
Run Code Online (Sandbox Code Playgroud)

注册功能

 public function …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5 php-7

-2
推荐指数
2
解决办法
50
查看次数

找不到类“App\Http\Controllers\DB”

我收到一个错误Class 'App\Http\Controllers\DB' not found。是否有改进建议?

laravel laravel-5

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