因此,当我在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'];
}
有任何想法吗?
最佳答案
使用这些说明:
protected $fillable = ['name'];
protected $fillable = ['surname'];
您多次声明相同的
$fillable
字段,并且每次将其设置为一个元素的数组。相反,您应该将一个字段声明为包含许多元素的数组:
protected $fillable = ['name', 'surname', 'street', 'city', 'postal', 'participants', 'colors1', 'colors2'];
关于php - Laravel 5 : Cannot redeclare App\Subscription::$fillable,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34962598/