小编Dmi*_*lys的帖子

SQLSTATE [HY000]:常规错误:1215无法添加外键约束Laravel

我试图创建一个外键使用artisan,但这个错误出现了.

[Illuminate\Database\QueryException]                                                                                                                                                                             
  SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `comments` add constraint `comments_comment_lot_id_foreign` foreign key (`comment_lot_id`) references `lots` (`lot_id`  
  ) on delete cascade) 
Run Code Online (Sandbox Code Playgroud)

这是我的迁移:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCommentsTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('comments', function (Blueprint $table) {
            $table->increments('id');
            $table->text('comment');
            $table->integer('comment_lot_id')->unsigned();
            $table->timestamps();
        });

        Schema::table('comments', function ($table) {
            $table->foreign('comment_lot_id')->references('lot_id')->on('lots')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     * …
Run Code Online (Sandbox Code Playgroud)

migration foreign-keys laravel-5

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

Vue.js 路由器查询数组

我想做的是使用 Vue.js 和路由器将数组从查询传递到后端。

所以我有这个方法:

submitForm () {
  this.$router.push({
    name: 'AuctionResult',
    query: {
      models: this.selectedModels.map(e => e.value)
    }
  })
},
Run Code Online (Sandbox Code Playgroud)

结果将是这样的查询:?models=MODEL1&models=MODEL2... 但是我怎样才能使输入看起来像数组,像这样:?models[]=MODEL1&models[]=MODEL2...???

我在文档中没有找到任何内容。

javascript vue-router vuejs2

6
推荐指数
1
解决办法
8123
查看次数

Laravel text area validation best practice

I am not sure what kind of validation I should use for comments in E-commerce website that I am currently developing. It is not much I want to validate but I'm worried about security.

So what is the best practice?

My code now looks like this:

$this->validate($request, [
    'comment' => 'max:1000',
]);
Run Code Online (Sandbox Code Playgroud)

Is it safe to leave it like that?

php laravel

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

我设置app:name后找不到Laravel 5.4类'App \ Providers \ AppServiceProvider'

我需要您的新手帮助。

在我的本地项目上,我使用命令 php artisan app:name xyz

然后我将其推入生产,但出现错误:

production.ERROR:Symfony \ Component \ Debug \ Exception \ FatalThrowableError:在/var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:612中找不到类'App \ Providers \ AppServiceProvider'

我该如何解决?

php laravel-5.4

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

检查 Laravel 集合中是否存在记录

我有控制器

public function users() {

 $users = User::all('id');

 return view('view', compact('users'))

}
Run Code Online (Sandbox Code Playgroud)

然后在我看来,我尝试检查是否$users有我需要的 id

@if (contains($users, Auth::user()->id)
   do something
@enif
Run Code Online (Sandbox Code Playgroud)

但什么也没有发生。如何检查集合是否具有我需要的 ID?

php laravel-5.4

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

Laravel getQueryString() 没有 &amp;

我正在尝试将包含部分 URL 的变量输出到我页面上的 Javascript 中。当我这样做时,它会将 any 更改&&amp;,这会破坏 URL。

我试过使用str_replace, html_entity_decodehtmlspecialchars_decode但结果总是相同&amp;而不是&.

我怎样才能得到它&而不是&amp;

这是我的控制器:

//here we catch the query
public function index(Request $request)
    {
        $input   = $request->getQueryString();

        return view('lots.browse')->withInput($input);
    }

// here we filter the ajax request
public function indexData(LotFilters $filters)
    {
       $lots  = Lot::filter($filters);

        return Datatables::eloquent($lots)->make(true);
    }
Run Code Online (Sandbox Code Playgroud)

这是我的观点:

<!-- Datatables -->
    <script type="text/javascript">
        $(document).ready(function(){
            $('#table').DataTable({
                searching: false,
                processing: true,
                serverSide: true,
                ajax: '{{  url("/data") …
Run Code Online (Sandbox Code Playgroud)

laravel-blade

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

Laravel“密码错误”错误消息

我在Laravel 5.4中创建一个登录功能,当密码不正确时,我想在视图中显示错误消息。另外,我还有一条自定义消息,用于帐户批准,因此这对我来说有点困难。同时,我将这些消息放在一起,但不是很友好。如何分开?

这是我的控制器:

public function login(Request $request)
{
    // validate the form data
    $this->validate($request, [
        'email' => 'required|email|exists:users,email',
        'password' => 'required|min:6'
    ]);

    // attempt to log
    if (Auth::attempt(['approve' => '1', 'email' => $request->email, 'password' => $request->password ], $request->remember)) {

        // if successful -> redirect forward
        return redirect()->intended(route('user.overview'));
    }

    // if unsuccessful -> redirect back
    return redirect()->back()->withInput($request->only('email', 'remember'))->withErrors([
        'approve' => 'Wrong password or this account not approved yet.',
    ]);
}
Run Code Online (Sandbox Code Playgroud)

结果,我想替换Wrong password or this account not approved yet为两个单独的消息:

如果密码错误,则显示: …

php laravel-5.4

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