当我在Laravel 5网站上发布帖子请求时,我有这个错误:
Cannot redeclare App\Subscription::$fillable
这是我的SubscriptionController.php文件。当我尝试发布到localhost / subscription时会导致错误,该调用调用我尝试创建Subscription类的store方法,但会导致错误。
我已经尝试在另一种方法中创建一个Subscription实例,但这会导致同样的问题。
<?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'];
}
有什么想法吗?
答案 0 :(得分:5)
使用这些说明:
protected $fillable = ['name'];
protected $fillable = ['surname'];
您多次声明相同的$fillable
字段,并且每次将其设置为一个元素的数组。
相反,您应该将一个字段声明为多个元素的数组:
protected $fillable = ['name', 'surname', 'street', 'city', 'postal', 'participants', 'colors1', 'colors2'];