【问题标题】:Laravel 5: Cannot redeclare App\Subscription::$fillableLaravel 5:无法重新声明 App\Subscription::$fillable
【发布时间】:2016-04-29 23:47:38
【问题描述】:

所以当我在我的 Laravel 5 网站上进行发布请求时出现此错误:

Cannot redeclare App\Subscription::$fillable

这是我的 SubscriptionController.php 文件。当我尝试发布到 localhost/subscription 时导致错误,它调用了我尝试创建 Subscription 类的 store 方法,但导致错误。

我已经尝试用另一种方法创建订阅实例,但这会导致同样的问题。

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Subscription;
use App\Http\Requests;
use App\Http\Requests\StoreSubscriptionRequest;
use App\Http\Controllers\Controller;

class SubscriptionController extends Controller
{
    public function __construct()
    {
        //$this->middleware('auth');
    }

    public function index(Request $request)
    {
        return view('subscriptions.index');
    }

    public function store(StoreSubscriptionRequest $request)
    {
        $sub = new Subscription;
    }
}

这是我的 Subscription.php 文件。

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Subscription extends Model
{
     protected $fillable = ['name'];
     protected $fillable = ['surname'];
     protected $fillable = ['street'];
     protected $fillable = ['city'];
     protected $fillable = ['postal'];
     protected $fillable = ['participants'];
     protected $fillable = ['colors1'];
     protected $fillable = ['colors2'];
}

有什么想法吗?

【问题讨论】:

  • 你试图重新声明同一个变量 8 次

标签: php laravel laravel-5 error-handling eloquent


【解决方案1】:

使用这些说明:

 protected $fillable = ['name'];
 protected $fillable = ['surname'];

您多次声明相同的$fillable 字段,并且每次将其设置为一个元素的数组。

您应该将一个字段声明为包含许多元素的数组:

protected $fillable = ['name', 'surname', 'street', 'city', 'postal', 'participants', 'colors1', 'colors2'];

【讨论】:

    猜你喜欢
    • 2021-05-19
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多