小编use*_*425的帖子

电话号码是整数还是字符串?

我想知道电话号码是否必须使用字符串或整数?

我已经尝试过,integer但验证时遇到问题。

... table->integer('phone'); ...

在我的验证中,我必须拥有 8 到 11 个字符。

我已经尝试过这个,但它不起作用:

'phone' => 'required|numeric|between:8,11',

我觉得那个string更好?

validation laravel laravel-5 laravel-validation

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

Laravel上的存储库模式

我想使用,Repository Pattern但是我在语法上受了限制。我想获取我的函数index()。

第一步,创建文件夹Repositories并创建文件AuteurRepository.php

在此处输入图片说明

在我的文件AuteurController中,我有以下内容:

public function index()
{
   $auteurs = Auteur::oldest()->paginate(5);
   return view('admin.auteurs.index', compact('auteurs'))
           ->with('i', (request()->input('page', 1)-1)*5);
}
Run Code Online (Sandbox Code Playgroud)

在我的模型中,我只有一个文件Auteur

protected $fillable = ['name', 'firstname'];
Run Code Online (Sandbox Code Playgroud)

我有两个问题:

1)如何在我的文件AuteurRepository中创建函数index()

我试过了吗?

<?php 

namespace App\Repositories; 
use App\Auteur; 

class AuteurRepository
{
    public function index()
    {
        return Auteur::oldest()->paginate(5);
    }
}


?>
Run Code Online (Sandbox Code Playgroud)

我的第二个问题是在我的AuteurController中,我不知道该怎么办?

我现在有这个

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Auteur;
use App\Repositories\AuteurRepository; 

class AuteurController extends Controller
{


    protected $auteurs;

    public function __construct(AuteurRepository …
Run Code Online (Sandbox Code Playgroud)

php design-patterns repository-pattern laravel

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

口才转换请求SQL

我想request在Laravel Eloquent中将其转换为以下内容。

select * from revision
where fk_motorbike = NumberMoto
and start_time between time_start_training and time_stop_training 
or start_stop between time_start_training and time_stop_training
Run Code Online (Sandbox Code Playgroud)

我在第二行之后陷入困境...

$Revision = Revision::where('fk_motorbike', $fk_motorbike)
->where('start_time', "<=", $time_start_training) ?
???
->first();
Run Code Online (Sandbox Code Playgroud)

我仍然是Laravel的初学者。

感谢您的帮助。

laravel laravel-5

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